Submission #827827

# Submission time Handle Problem Language Result Execution time Memory
827827 2023-08-16T19:53:56 Z ikaurov Ancient Machine 2 (JOI23_ancient2) C++17
37 / 100
48 ms 476 KB
#include "ancient2.h"
#include <bits/stdc++.h>
using namespace std;
#define all(arr) (arr).begin(), (arr).end()
#define ll long long
#define ld long double
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define endl '\n'

vector<int> nums = {4, 5, 7, 9};
bool first1;

int query(std::vector<int> a, std::vector<int> b){
  if (first1) swap(a, b);
  return Query(sz(a), a, b);
}

int ask(int idx, vector<vector<int>> a, bool type){
  if (a[0].empty()){
    a[0] = a[1] = {1};
  }
  if (idx == -1){
    int to_add = sz(nums);
    for (int i = 0; i < to_add; i++){
      a[type].pb(sz(a[type]) + 1);
      a[type ^ 1].pb(sz(a[type ^ 1]) + 1 + to_add);
    }
    for (int i = 0; i < to_add + 1; i++) a[0].pb(sz(a[0])), a[1].pb(sz(a[1]));
    int node = query(a[0], a[1]);
    int midnode = sz(a[0]) - to_add - 1;
    if (node == midnode) return 0;
    else if (node < midnode) return node - (midnode - to_add) + 1;
    else return node - midnode;
  }
  int to_add = nums[idx];
  for (int i = 0; i < to_add; i++) a[type].pb(sz(a[type]) + 1), a[type ^ 1].pb(sz(a[type ^ 1]) + to_add);
  a[type].back() = sz(a[type]) - to_add;
  for (int i = 0; i < to_add; i++) a[0].pb(sz(a[0])), a[1].pb(sz(a[1]));
  int node = query(a[0], a[1]);
  return (node - (sz(a[0]) - to_add * 2) + 1) % to_add;
}

int reconstruct(vector<int> mods){
  for (int i = 0;; i++){
    bool good = 1;
    for (int j = 0; j < sz(nums); j++){
      good &= (i % nums[j] == mods[j]);
    }
    if (good) return i;
  }
}

string Solve(int n){
  first1 = (Query(3, {1, 1, 2}, {2, 1, 2}) == 2);
  vector<int> blocks;
  while (accumulate(all(blocks), 0) < n - 1){
    vector<vector<int>> a(2);
    bool markedbefore = 1;
    for (int i = 0; i < sz(blocks); i++){
      if (i < sz(blocks) - 1 && blocks[i] == 1 && !markedbefore){
        markedbefore = 1;
        continue;
      }
      markedbefore = 0;
      bool type = (i & 1);
      a[type].pb(sz(a[type]));
      a[type ^ 1].pb(sz(a[type ^ 1]) + 1);
    }
    vector<int> mods(sz(nums));
    int val = ask(-1, a, sz(blocks) & 1);
    if (val){
      blocks.pb(val);
      continue;
    }
    for (int i = 0; i < sz(mods); i++) mods[i] = ask(i, a, sz(blocks) & 1);
    blocks.pb(reconstruct(mods));
  }
  if (accumulate(all(blocks), 0) == n - 1) blocks.pb(1);
  string ans;
  for (int i = 0; i < sz(blocks); i++){
    ans += string(blocks[i], '0' + ((i & 1) ^ first1));
  }
  return ans;
}
# Verdict Execution time Memory Grader output
1 Partially correct 20 ms 412 KB Output is partially correct
2 Partially correct 15 ms 360 KB Output is partially correct
3 Partially correct 10 ms 428 KB Output is partially correct
4 Partially correct 7 ms 400 KB Output is partially correct
5 Partially correct 14 ms 396 KB Output is partially correct
6 Correct 3 ms 336 KB Output is correct
7 Partially correct 21 ms 428 KB Output is partially correct
8 Partially correct 46 ms 364 KB Output is partially correct
9 Partially correct 14 ms 476 KB Output is partially correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 3 ms 312 KB Output is correct
13 Correct 5 ms 300 KB Output is correct
14 Correct 4 ms 208 KB Output is correct
15 Correct 3 ms 208 KB Output is correct
16 Partially correct 48 ms 460 KB Output is partially correct
17 Partially correct 43 ms 468 KB Output is partially correct
18 Partially correct 39 ms 448 KB Output is partially correct
19 Partially correct 46 ms 400 KB Output is partially correct
20 Partially correct 46 ms 408 KB Output is partially correct
21 Partially correct 45 ms 336 KB Output is partially correct
22 Partially correct 11 ms 416 KB Output is partially correct
23 Partially correct 20 ms 420 KB Output is partially correct
24 Partially correct 13 ms 336 KB Output is partially correct
25 Partially correct 15 ms 388 KB Output is partially correct
26 Partially correct 12 ms 372 KB Output is partially correct
27 Partially correct 13 ms 364 KB Output is partially correct
28 Partially correct 12 ms 356 KB Output is partially correct
29 Partially correct 11 ms 360 KB Output is partially correct
30 Partially correct 18 ms 388 KB Output is partially correct
31 Partially correct 10 ms 340 KB Output is partially correct
32 Correct 4 ms 320 KB Output is correct
33 Correct 4 ms 208 KB Output is correct
34 Correct 2 ms 304 KB Output is correct
35 Correct 2 ms 208 KB Output is correct
36 Correct 1 ms 208 KB Output is correct
37 Correct 1 ms 208 KB Output is correct
38 Partially correct 30 ms 448 KB Output is partially correct
39 Partially correct 26 ms 444 KB Output is partially correct
40 Partially correct 26 ms 352 KB Output is partially correct
41 Partially correct 28 ms 388 KB Output is partially correct
42 Partially correct 20 ms 440 KB Output is partially correct
43 Partially correct 21 ms 432 KB Output is partially correct
44 Partially correct 22 ms 352 KB Output is partially correct
45 Partially correct 21 ms 448 KB Output is partially correct
46 Partially correct 22 ms 452 KB Output is partially correct
47 Partially correct 26 ms 336 KB Output is partially correct
48 Partially correct 19 ms 464 KB Output is partially correct
49 Partially correct 21 ms 392 KB Output is partially correct
50 Partially correct 30 ms 448 KB Output is partially correct
51 Partially correct 21 ms 336 KB Output is partially correct
52 Partially correct 21 ms 404 KB Output is partially correct
53 Partially correct 23 ms 336 KB Output is partially correct
54 Partially correct 22 ms 348 KB Output is partially correct
55 Partially correct 21 ms 416 KB Output is partially correct
56 Partially correct 20 ms 436 KB Output is partially correct
57 Correct 6 ms 208 KB Output is correct
58 Partially correct 21 ms 428 KB Output is partially correct
59 Correct 1 ms 208 KB Output is correct
60 Partially correct 8 ms 348 KB Output is partially correct
61 Partially correct 14 ms 396 KB Output is partially correct
62 Partially correct 21 ms 420 KB Output is partially correct
63 Partially correct 24 ms 376 KB Output is partially correct