I have bug in my code. It always fails test set 2 and can't figure out 
where I'm doing wrong. If you can spot where I'm doing wrong could you 
please tell me? Thank you.

from sys import stdout

query_num = 1
def query(i):
    global query_num
    query_num += 1
    print(i+1)
    stdout.flush()
    return int(input())

def flip(ans):
    for i, bit in enumerate(ans):
        if bit > -1:
            ans[i] ^= 1


T, B = map(int, input().split())
for _ in range(T):
    ans = [-1] * B
    s = d = -1  # same pair, diff pair indices
    for i in range(B//2):
        if query_num > 1 and query_num % 10 == 1:
            if s > -1 and d > -1:
                same, diff = query(s), query(d)
                if same != ans[s] and diff != ans[d]:
                    flip(ans)
                elif same != ans[s]:
                    ans.reverse()
                    flip(ans)
                elif diff != ans[d]:
                    ans.reverse()
            elif s > -1:
                if query(s) != ans[s]:
                    flip(ans)
                query(s)
            elif d > -1:
                if query(d) != ans[d]:
                    flip(ans)
                query(d)
        j = B-1-i
        ans[i], ans[j] = query(i), query(j)
        if ans[i] == ans[j]:
            s = i
        else:
            d = i
    print(''.join(str(bit) for bit in ans))
    stdout.flush()
    if input() == 'N':
        exit()

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/f78da024-3eee-4b14-8dd4-9c8799db73f4%40googlegroups.com.

Reply via email to