sacgajcvs

Untitled

Feb 12th, 2022
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.74 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define N 1000
  5.  
  6. static int ranki[N];
  7. static int isused[N];
  8.  
  9. #define MAXQUERY 1000000
  10.  
  11. static bool okay;
  12. static int querycount;
  13.  
  14. void play(int mRank[N]);
  15.  
  16. int query(int K, int mSub[], int mOpt) {
  17. if(!okay || K < 5 || K > N || (mOpt != 0 && mOpt != 1) || querycount >= MAXQUERY) {
  18. okay = false;
  19. return -1;
  20. }
  21. ++querycount;
  22. if(mOpt == 0) {
  23. int ret = N - 1;
  24. for(int k = 0; k < K; ++k) {
  25. if(mSub[k] < 0 || mSub[k] >= N || isused[mSub[k]] == querycount) {
  26. okay = false;
  27. return -1;
  28. }
  29. isused[mSub[k]] = querycount;
  30. if(ret > ranki[mSub[k]]) {
  31. ret = ranki[mSub[k]];
  32. }
  33. }
  34. return ret;
  35. } else {
  36. int ret = 0;
  37. for(int k = 0; k < K; ++k) {
  38. if(mSub[k] < 0 || mSub[k] >= N || isused[mSub[k]] == querycount) {
  39. okay = false;
  40. return -1;
  41. }
  42. isused[mSub[k]] = querycount;
  43. if(ret < ranki[mSub[k]]) {
  44. ret = ranki[mSub[k]];
  45. }
  46. }
  47. return ret;
  48. }
  49. }
  50.  
  51. static int callout;
  52.  
  53. static bool run() {
  54. int mLimit;
  55. int mRank[N];
  56. okay = true;
  57. for(int c = 0; c < 10; c++) {
  58. mLimit = 1200;
  59. for(int i = 0; i < N; i++) {
  60. scanf("%d", &ranki[i]);
  61. }
  62. querycount = 0;
  63. for(int i = 0; i < N; i++) {
  64. isused[i] = 0;
  65. }
  66. if(okay) {
  67. play(mRank);
  68. }
  69. if(mLimit < querycount) {
  70. okay = false;
  71. }
  72. if(okay) {
  73. for(int i = 0; i < N; i++) {
  74. if(ranki[i] != mRank[i]) {
  75. okay = false;
  76. }
  77. }
  78. }
  79. callout += querycount;
  80. }
  81. return okay;
  82. }
  83.  
  84. int main()
  85. {
  86. int T, MARK;
  87. scanf("%d %d", &T, &MARK);
  88.  
  89. int totalcount = 0;
  90. for(int tc = 1; tc <= T; tc++) {
  91. int score;
  92. callout = 0;
  93. score = run() ? MARK : 0;
  94. printf("%d %d %d\n", tc, score, callout);
  95. totalcount += callout;
  96. }
  97. printf("totalcount = %d, average = %.3f\n", totalcount, (totalcount / (T * 10.0)));
  98. return 0;
  99. }
  100.  
  101. // main code
  102.  
  103. int ask_query(vector<int>& arr, int type) {
  104. int b[arr.size()];
  105. for(int i = 0; i < arr.size(); i++) {
  106. b[i] = arr[i];
  107. }
  108. return query(arr.size(), b, type);
  109. }
  110.  
  111. int doit(int num, set<int>& st) {
  112. int l = 0, r = N - 1, mid, out;
  113. while(l <= r) {
  114. mid = (l + r) / 2;
  115. vector<int> arr;
  116. for(int i = l; i <= mid; i++) {
  117. if(st.find(i) == st.end()) {
  118. arr.push_back(i);
  119. }
  120. }
  121. if(arr.size() < 5) {
  122. break;
  123. }
  124. out = ask_query(arr, 0);
  125. if(out == num) {
  126. r = mid;
  127. } else {
  128. l = mid + 1;
  129. }
  130. }
  131. vector<int> ext;
  132. for(int i = 0; i < N && ext.size() < 4; i++) {
  133. if(st.find(i) != st.end() || (i <= r && i >= l)) {
  134. continue;
  135. }
  136. ext.push_back(i);
  137. }
  138. for(int i = l; i <= r; i++) {
  139. ext.push_back(i);
  140. out = ask_query(ext, 0);
  141. if(out == num) {
  142. return i;
  143. }
  144. ext.pop_back();
  145. }
  146. assert(false);
  147. }
  148.  
  149. void play(int mRank[N]) {
  150. set<int> st;
  151. vector<int> ini;
  152. int ret;
  153. for(int i = 0; i < 4; i++) {
  154. ret = doit(i, st);
  155. ini.push_back(ret);
  156. st.insert(ret);
  157. mRank[ret] = i;
  158. }
  159. vector<int> ext;
  160. for(auto i: st) {
  161. ext.push_back(i);
  162. }
  163. for(int i = 0; i < N; i++) {
  164. if(st.find(i) != st.end()) {
  165. continue;
  166. }
  167. ext.push_back(i);
  168. mRank[i] = ask_query(ext, 1);
  169. ext.pop_back();
  170. }
  171. }
Advertisement
Add Comment
Please, Sign In to add comment