fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. #define print(a) for(auto x : a) cout << x << " "; cout << endl
  6.  
  7.  
  8. const int M = 1000000007;
  9. const int N = 3e5+9;
  10. const int INF = 2e9+1;
  11. const int LINF = 2000000000000000001;
  12.  
  13. inline int power(int a, int b, int mod=M) {
  14. int x = 1;
  15. a %= mod;
  16. while (b) {
  17. if (b & 1) x = (x * a) % mod;
  18. a = (a * a) % mod;
  19. b >>= 1;
  20. }
  21. return x;
  22. }
  23.  
  24.  
  25. //_ ***************************** START Below *******************************
  26.  
  27. //* Change this to false => before submitting to cf
  28. bool testing = true;
  29.  
  30. int n = 10;
  31. vector<int> toGuess = {2, 4, 6, 7, 9, 10};
  32.  
  33. bool interactor(int query){
  34. auto it = lower_bound(begin(toGuess), end(toGuess), query);
  35.  
  36. if(it != toGuess.end() && *it == query ) return true;
  37. return false;
  38. }
  39.  
  40. bool askQuery(int x){
  41. cout << "? " << x << endl;
  42.  
  43. //* Custom interactor for testing ourself
  44. if(testing){
  45. cout << interactor(x) << endl;
  46. return interactor(x);
  47. }
  48.  
  49. //* Codeforces Judge interacts
  50. int yesNo;
  51. cin >> yesNo;
  52. return yesNo;
  53.  
  54. }
  55.  
  56.  
  57. int consistency(){
  58.  
  59.  
  60.  
  61. //* seed random with random_device
  62. // random_device rd;
  63. // mt19937 gen(rd());
  64.  
  65. //* seed random with system clock
  66. mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
  67.  
  68. uniform_int_distribution<> distrib(1, n);
  69.  
  70.  
  71. for(int i=1; i<=100; i++){
  72.  
  73. int randIndx = distrib(gen);
  74.  
  75. if(askQuery(randIndx) == true) return randIndx;
  76. }
  77.  
  78. }
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87. void solve() {
  88. //* String buffer issue in interactive
  89. // cout << "! " << consistency() << endl;
  90.  
  91. int ans = consistency();
  92. cout << "! " << ans << endl;
  93.  
  94. }
  95.  
  96.  
  97.  
  98.  
  99.  
  100. int32_t main() {
  101. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  102.  
  103. solve();
  104.  
  105. return 0;
  106. }
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
? 2
1
! 2