Submission #890736

# Submission time Handle Problem Language Result Execution time Memory
890736 2023-12-21T20:29:23 Z null_awe Ancient Machine 2 (JOI23_ancient2) C++17
10 / 100
75 ms 2076 KB
#include <vector>
#include <algorithm>
#include <iostream>
#include "ancient2.h"
using namespace std;

string Solve(int N) {
  string ans = "";
  while ((int) ans.size() < 1) {
    vector<int> c(2);
    for (int i = 0; i < (int) ans.size(); ++i) ++c[ans[i] - '0'];
    int todo = min(c[0], c[1]);
    if (todo > 99) break;
    vector<int> a(todo + 3);
    for (int i = 0; i < todo; ++i) a[i] = i + 1;
    vector<int> b(todo + 3);
    for (int i = 0; i < todo; ++i) b[i] = i;
    a[todo] = a[todo + 1] = todo + 1, a[todo + 2] = todo + 2;
    b[todo] = b[todo + 2] = todo + 2, b[todo + 1] = todo + 1;
    if (c[1] < c[0]) swap(a, b);
    int x = Query(todo + 3, a, b);
    if (x == a[todo]) ans += "0";
    else ans += "1";
  }
  if ((int) ans.size() == N) return ans;
  while ((int) ans.size() < N) {
    vector<int> c(2);
    for (int i = 0; i < (int) ans.size(); ++i) ++c[ans[i] - '0'];
    int todo = c[ans.back() - '0'];
    if (todo > 0 && todo < 10000) {
      vector<int> a(todo + 3);
      for (int i = 0; i < todo; ++i) a[i] = i + 1;
      vector<int> b(todo + 3);
      for (int i = 0; i < todo; ++i) b[i] = i;
      a[todo] = a[todo + 1] = todo + 1, a[todo + 2] = todo + 2;
      b[todo] = b[todo + 2] = todo + 2, b[todo + 1] = todo + 1;
      if (ans.back() == '1') swap(a, b);
      int x = Query(todo + 3, a, b);
      if (x == a[todo]) ans += "0";
      else ans += "1";
      continue;
    }

    vector<int> a(102, -1);
    vector<int> b(102, -1);
    a[100] = b[100] = 100;
    a[101] = b[101] = 101;
    for (int i = 0; i < 98; ++i) a[i] = i + 1, b[i] = i + 1;
    a[98] = 3, b[98] = 7;
    int idx = 0;
    for (int i = 0; i < (int) ans.size(); ++i) {
      ++idx;
      if (idx > 98) {
        if (ans[i] == '0') idx = a[98];
        else idx = b[98];
      }
    }
    if (ans.back() == '1') {
      a[99] = idx;
      a[idx - 1] = 99;
      if (idx == a[98]) a[98] = 99;
      a[idx] = 100;
    } else {
      b[99] = idx;
      b[idx - 1] = 99;
      if (idx == b[98]) b[98] = 99;
      b[idx] = 100;
    }
    for (int i = 0; i < 102; ++i) {
      if (a[i] < 0) a[i] = 101;
      if (b[i] < 0) b[i] = 101;
    }
    int x = Query(102, a, b);
    if (x != 100) ans += string(1, ans.back());
    else ans += string(1, (char) ('0' + '1' - ans.back()));
    // cout << "has " << ans << '\n';
  }
  return ans;
}
# Verdict Execution time Memory Grader output
1 Partially correct 43 ms 1276 KB Output is partially correct
2 Partially correct 41 ms 800 KB Output is partially correct
3 Partially correct 41 ms 1056 KB Output is partially correct
4 Partially correct 42 ms 572 KB Output is partially correct
5 Partially correct 43 ms 820 KB Output is partially correct
6 Partially correct 41 ms 568 KB Output is partially correct
7 Partially correct 44 ms 708 KB Output is partially correct
8 Partially correct 40 ms 2076 KB Output is partially correct
9 Partially correct 41 ms 572 KB Output is partially correct
10 Partially correct 43 ms 816 KB Output is partially correct
11 Partially correct 43 ms 1564 KB Output is partially correct
12 Partially correct 41 ms 812 KB Output is partially correct
13 Partially correct 43 ms 1060 KB Output is partially correct
14 Partially correct 41 ms 816 KB Output is partially correct
15 Partially correct 42 ms 1064 KB Output is partially correct
16 Partially correct 43 ms 816 KB Output is partially correct
17 Partially correct 41 ms 1060 KB Output is partially correct
18 Partially correct 41 ms 984 KB Output is partially correct
19 Partially correct 43 ms 564 KB Output is partially correct
20 Partially correct 41 ms 1324 KB Output is partially correct
21 Partially correct 43 ms 980 KB Output is partially correct
22 Partially correct 41 ms 564 KB Output is partially correct
23 Partially correct 45 ms 828 KB Output is partially correct
24 Partially correct 46 ms 784 KB Output is partially correct
25 Partially correct 41 ms 1072 KB Output is partially correct
26 Partially correct 44 ms 1316 KB Output is partially correct
27 Partially correct 41 ms 1568 KB Output is partially correct
28 Partially correct 42 ms 984 KB Output is partially correct
29 Partially correct 41 ms 820 KB Output is partially correct
30 Partially correct 42 ms 812 KB Output is partially correct
31 Partially correct 42 ms 1224 KB Output is partially correct
32 Partially correct 42 ms 964 KB Output is partially correct
33 Partially correct 41 ms 992 KB Output is partially correct
34 Partially correct 44 ms 804 KB Output is partially correct
35 Partially correct 43 ms 1300 KB Output is partially correct
36 Partially correct 45 ms 564 KB Output is partially correct
37 Partially correct 44 ms 1244 KB Output is partially correct
38 Partially correct 44 ms 1536 KB Output is partially correct
39 Partially correct 41 ms 812 KB Output is partially correct
40 Partially correct 41 ms 816 KB Output is partially correct
41 Partially correct 46 ms 968 KB Output is partially correct
42 Partially correct 41 ms 720 KB Output is partially correct
43 Partially correct 42 ms 760 KB Output is partially correct
44 Partially correct 41 ms 1048 KB Output is partially correct
45 Partially correct 41 ms 1068 KB Output is partially correct
46 Partially correct 41 ms 1296 KB Output is partially correct
47 Partially correct 42 ms 1052 KB Output is partially correct
48 Partially correct 43 ms 564 KB Output is partially correct
49 Partially correct 43 ms 1320 KB Output is partially correct
50 Partially correct 40 ms 804 KB Output is partially correct
51 Partially correct 46 ms 700 KB Output is partially correct
52 Partially correct 42 ms 1004 KB Output is partially correct
53 Partially correct 41 ms 1076 KB Output is partially correct
54 Partially correct 41 ms 1076 KB Output is partially correct
55 Partially correct 42 ms 1316 KB Output is partially correct
56 Partially correct 52 ms 1264 KB Output is partially correct
57 Partially correct 69 ms 804 KB Output is partially correct
58 Partially correct 44 ms 1080 KB Output is partially correct
59 Partially correct 75 ms 564 KB Output is partially correct
60 Partially correct 65 ms 1220 KB Output is partially correct
61 Partially correct 59 ms 1112 KB Output is partially correct
62 Partially correct 54 ms 1152 KB Output is partially correct
63 Partially correct 47 ms 1116 KB Output is partially correct