Skip to content

Instantly share code, notes, and snippets.

@kburaya
Created January 16, 2018 15:35
Show Gist options
  • Save kburaya/61087eb7fac4ea35d8e00585676545ec to your computer and use it in GitHub Desktop.
Save kburaya/61087eb7fac4ea35d8e00585676545ec to your computer and use it in GitHub Desktop.
from sys import stdin
from random import shuffle
def main():
input = stdin.readline()
n = int(input.split(' ')[0])
f = int(input.split(' ')[1])
indexes = [i for i in range(n)]
shuffle(indexes)
next_query = ''
i = 0
while i < n:
if f == n:
break
if i == n - 1:
print('%s%d\n' % (next_query, indexes[i] + 1))
break
j = i + 1
print('%s%d %d\n' % (next_query, indexes[i] + 1, indexes[j] + 1))
next_query = ''
line = stdin.readline()
if 'Accepted' in line:
return
f_new = int(line)
if f_new - f == 2:
f = f_new
i = j + 1
continue
elif f_new - f == -2:
next_query = '%d %d ' % (indexes[i] + 1, indexes[j] + 1)
f = f_new + 2
i = j + 1
continue
else: # f_new - f can be only zero
print ('%d\n' % (indexes[i] + 1))
line = stdin.readline()
if 'Accepted' in line:
return
f_new = int(line)
if f_new - f == -1:
next_query = '%d %d ' % (indexes[i] + 1, indexes[j] + 1)
f = f_new + 1
i = j + 1
continue
stdin.readline()
return
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment