Skip to content

Instantly share code, notes, and snippets.

@kburaya
Created January 16, 2018 18:27
Show Gist options
  • Save kburaya/dc526af8a443457a7f9d975be2bcf01f to your computer and use it in GitHub Desktop.
Save kburaya/dc526af8a443457a7f9d975be2bcf01f to your computer and use it in GitHub Desktop.
from sys import stdin
from sys import stdout
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 i == n - 1:
if f != n:
print('%s%d' % (next_query, indexes[i] + 1), flush=True)
stdin.readline()
return
j = i + 1
print('%s%d %d' % (next_query, indexes[i] + 1, indexes[j] + 1), flush=True)
next_query = ''
line = stdin.readline()
f_new = int(line)
if f_new == n:
return
elif 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' % (indexes[i] + 1), flush=True)
stdout.flush()
line = stdin.readline()
f_new = int(line)
if f_new == n:
return
if f_new - f == -1 or f_new - f == 0:
next_query = '%d %d ' % (indexes[i] + 1, indexes[j] + 1)
f = f_new + 1
i = j + 1
continue
return
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment