from sys import stdin, stdout def try_rhyme(tutaj, licz_tutaj, start, koniec, tab): while tutaj <= koniec: if tutaj == koniec: if licz_tutaj == 0: return True else: return False # we have next toy here licz_tutaj = tab[tutaj+1] - licz_tutaj - 1 tutaj += 1 if licz_tutaj < -1: return False elif licz_tutaj == -1: if tutaj == koniec: return True return False def process_day(): n = int(stdin.readline()) tab = [int(s) for s in stdin.readline().split()] + [0] start = 0 while tab[start] == 0: start += 1 koniec = len(tab) - 1 while tab[koniec] == 0: koniec -= 1 # try starting at start tutaj = start licz_tutaj = tab[tutaj] - 1 output = try_rhyme(tutaj, licz_tutaj, start, koniec, tab) if output: return True # try starting at start + 1 if start == koniec: # nowhere to start return False tutaj = start + 1 licz_tutaj = tab[tutaj] - 1 - tab[tutaj-1] if licz_tutaj < -1: return False if licz_tutaj == -1: if tutaj == koniec: return True return False output = try_rhyme(tutaj, licz_tutaj, start, koniec, tab) return output t = int(stdin.readline()) for _ in range(t): output = process_day() if output: stdout.write("TAK\n") else: stdout.write("NIE\n")
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | from sys import stdin, stdout def try_rhyme(tutaj, licz_tutaj, start, koniec, tab): while tutaj <= koniec: if tutaj == koniec: if licz_tutaj == 0: return True else: return False # we have next toy here licz_tutaj = tab[tutaj+1] - licz_tutaj - 1 tutaj += 1 if licz_tutaj < -1: return False elif licz_tutaj == -1: if tutaj == koniec: return True return False def process_day(): n = int(stdin.readline()) tab = [int(s) for s in stdin.readline().split()] + [0] start = 0 while tab[start] == 0: start += 1 koniec = len(tab) - 1 while tab[koniec] == 0: koniec -= 1 # try starting at start tutaj = start licz_tutaj = tab[tutaj] - 1 output = try_rhyme(tutaj, licz_tutaj, start, koniec, tab) if output: return True # try starting at start + 1 if start == koniec: # nowhere to start return False tutaj = start + 1 licz_tutaj = tab[tutaj] - 1 - tab[tutaj-1] if licz_tutaj < -1: return False if licz_tutaj == -1: if tutaj == koniec: return True return False output = try_rhyme(tutaj, licz_tutaj, start, koniec, tab) return output t = int(stdin.readline()) for _ in range(t): output = process_day() if output: stdout.write("TAK\n") else: stdout.write("NIE\n") |