Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Interactive GCJ

a guest Apr 9th, 2020 137 in 307 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import copy
  2. import sys
  3. input = lambda: sys.stdin.readline().rstrip()
  4.  
  5. def read():
  6.     x = input()
  7.     if x=='N':
  8.         exit(0)
  9.     return x
  10.  
  11. def flip(B):
  12.     for i in range(len(B)):
  13.         if B[i] == '1':
  14.             B[i] = '0'
  15.         elif B[i] == '0':
  16.             B[i] = '1'
  17.  
  18. def solve():
  19.     B = [None for i in range(b)]
  20.     firstEqual,firstDifferent = -1,-1
  21.     queries,i = 0,0
  22.     while i < b//2:
  23.         if queries>0 and queries%10==0:
  24.             # check for flipped
  25.             if firstEqual != -1:
  26.                 print(str(firstEqual+1), flush=True)
  27.                 queries += 1
  28.                 x = read()
  29.                 if x != B[firstEqual]:
  30.                     flip(B)
  31.             # check reverse
  32.             if firstDifferent != -1:
  33.                 print(str(firstDifferent+1), flush=True)
  34.                 queries += 1
  35.                 x = read()
  36.                 if x != B[firstDifferent]:
  37.                     B=B[::-1]
  38.             continue
  39.         if queries % 10 == 9:
  40.             # dummy query because we read 2 by 2
  41.             print(str(1), flush=True)
  42.             queries += 1
  43.             read()
  44.             continue
  45.         print(str(i+1), flush=True)
  46.         queries += 1
  47.         B[i] = read()
  48.         print(str(b-i), flush=True)
  49.         queries += 1
  50.         B[-i-1] = read()
  51.         if B[i]==B[-i-1] and firstEqual == -1:
  52.             firstEqual = i
  53.         if B[i]!=B[-i-1] and firstDifferent == -1:
  54.             firstDifferent = i
  55.         i += 1
  56.     print(''.join(B), flush=True)
  57.     read() # read Y
  58.  
  59.  
  60. tests, b = map(int, input().split())
  61. for test in range(1, tests+1):
  62.     solve()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top