Created
July 6, 2018 09:05
-
-
Save szalai1/26cc97380ba98248f3d02a974b106e25 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python | |
#https://code.google.com/codejam/contest/3004486/dashboard#s=p1 | |
import sys | |
def deduplicate(train): | |
prev = train[0] | |
deduped = [prev] | |
for i in range(1, len(train)): | |
if train[i] != prev: | |
prev = train[i] | |
deduped.append(train[i]) | |
return "".join(deduped) | |
def adjacentyCheck(train): | |
# train = deduplicate(train) | |
m = {} | |
for c in train: | |
if c in m: | |
return False | |
m[c]=1 | |
return True | |
def main(): | |
T = int(raw_input()) | |
for t in range(T): | |
number_of_trains = int(raw_input()) | |
trains = raw_input().split(" ") | |
for train in range(len(trains)): | |
trains[train] = deduplicate(trains[train]) | |
inside = [] | |
if len(trains[train]) > 2: | |
if trains[train][0] == trains[train][-1]: | |
print t | |
inside.append(trains[train][1:-1]) | |
if not adjacentyCheck("".join(inside)): | |
print t | |
# print trains | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment