fork download
  1. #include <iostream>
  2. #include <sstream>
  3. #include <fstream>
  4. #include <string>
  5. #include <vector>
  6. #include <deque>
  7. #include <queue>
  8. #include <stack>
  9. #include <set>
  10. #include <map>
  11. #include <algorithm>
  12. #include <functional>
  13. #include <utility>
  14. #include <bitset>
  15. #include <cmath>
  16. #include <cstdlib>
  17. #include <ctime>
  18. #include <cstdio>
  19.  
  20. using namespace std;
  21.  
  22. #define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
  23. #define snuke(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
  24.  
  25. int Q = 0;
  26. int sum[1010];
  27.  
  28. int q[1010][1010];
  29.  
  30. int query(int L, int R){
  31. if(q[L][R] != -1) return q[L][R];
  32.  
  33. /* printf("? %d %d\n", L + 1, R);
  34. fflush(stdout);
  35. int ans;
  36. scanf("%d", &ans); */
  37.  
  38. int ans = sum[R] - sum[L];
  39. if(rand() % 2 == 0) ans = rand() % (R - L + 1);
  40. Q++;
  41.  
  42. return q[L][R] = ans;
  43. }
  44.  
  45. int get_char(int id){
  46. int i;
  47. int zero = 0, one = 0;
  48.  
  49. int L = id;
  50. int R = id + 1;
  51.  
  52. if(id < 500){
  53. for(i=1000;;i--){
  54. int tmp = query(L, i) - query(R, i);
  55. if(tmp == 0) zero++;
  56. if(tmp == 1) one++;
  57. if(abs(zero - one) >= 3) break;
  58. }
  59. } else {
  60. for(i=0;;i++){
  61. int tmp = query(i, R) - query(i, L);
  62. if(tmp == 0) zero++;
  63. if(tmp == 1) one++;
  64. if(abs(zero - one) >= 3) break;
  65. }
  66. }
  67.  
  68. return ((zero > one) ? 0 : 1);
  69. }
  70.  
  71. int main(void){
  72. int i,j;
  73.  
  74. srand(314422);
  75. REP(i,1000) sum[i+1] = sum[i] + rand() % 2;
  76.  
  77. REP(i,1010) REP(j,1010) q[i][j] = -1;
  78.  
  79. string ans;
  80. REP(i,1000) ans += (char)('0' + get_char(i));
  81.  
  82. // cout << "! " << ans << endl;
  83.  
  84. cout << Q << endl;
  85.  
  86. int tmp = 0;
  87. REP(i,1000){
  88. tmp += ans[i] - '0';
  89. if(tmp != sum[i+1]) cout << "angry" << endl;
  90. }
  91.  
  92. return 0;
  93. }
  94.  
Success #stdin #stdout 0s 19224KB
stdin
Standard input is empty
stdout
14697