# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
827827 | ikaurov | Ancient Machine 2 (JOI23_ancient2) | C++17 | 48 ms | 476 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|---|---|---|---|
Fetching results... |