EPS/2024/02/05-02-24/c.py

36 lines
646 B
Python
Raw Normal View History

2024-04-15 13:45:30 +02:00
import sys
def ask(a):
print(a)
sys.stdout.flush()
return int(input())
def main():
# max distance, size of p
m, n = [int(i) for i in input().split()]
answers = []
for i in range(n):
a = ask(m)
if a == 0:
return
answers.append(a)
asked = n
ppos = 0
lower, upper = 1, m-1
while asked < 60:
curr = lower + (upper-lower)//2
a = ask(curr)
asked += 1
if a*answers[ppos%n] == 1:
upper = curr -1
elif a*answers[ppos%n] == -1:
lower = curr +1
else:
return
ppos += 1
main()