fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int p[50];
  5. int main(){
  6. int n, m;
  7. cin >> n >> m;
  8. for(int i = 1; i <= n; i++){
  9. int y = m;
  10. cout << y << "\n";
  11. fflush(stdout);
  12. int x;
  13. cin >> x;
  14. if(x == 0)
  15. exit(0);
  16. if(x == -1)
  17. p[i]++;
  18. }
  19. int lo = 0, hi = m + 1, mid, i = 0;
  20. while(hi - lo > 1){
  21. i++;
  22. mid = hi + lo >> 1;
  23. int y = mid;
  24. cout << y << "\n";
  25. fflush(stdout);
  26. int x;
  27. cin >> x;
  28. if(x == 0)
  29. exit(0);
  30. if(!p[i])
  31. x = -x;
  32. if(x == -1)
  33. hi = mid;
  34. else
  35. lo = mid;
  36. }
  37.  
  38. }
Success #stdin #stdout 0s 4292KB
stdin
Standard input is empty
stdout
11005
16508
19259
20635
21323
21667
21839
21925
21968
21989
22000
22005
22008
22009
22010