# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1073299 | vjudge1 | Tricks of the Trade (CEOI23_trade) | C++17 | 0 ms | 0 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 "avoid.h"
#include <vector>
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using ld = long double;
//#define int ll
#define sz(x) ((int)(x).size())
using pii = pair<int,int>;
using tii = tuple<int,int,int>;
int cif(int a, int c) {
return (a & (1 << c)) > 0;
}
std::pair<int, int> scout(int lol, int H) {
if(lol == 10 && H == 1) {
for(int i = 0; i < 10; i++) {
vector<int> a, b;
for(int j = 1; j <= 1000; j++)
(!(j & (1 << i))? a : b).emplace_back(j);
send(a);
}
auto T = wait();
vector<int> uncertain;
int common = 0;
for(int i = 0, bit = 0; i < sz(T); bit++, i += 1) {
common |= (T[i]? 0 : (1 << bit));
}
return pii{common,common};
}
if(lol == 20 && H == 20) {
int L = 0, R = 0;
for(int bit = 0; bit < 10; bit++) {
vector<int> a;
for(int i = 1; i <= 1000; i++)
if((((1 << bit) - 1) & i) == L && (cif(i, bit) == 0)) a.emplace_back(i);
send(a);
int t = wait()[0] ^ 1;
L |= (t << bit);
a.clear();
for(int i = 1; i <= 1000; i++)
if((((1 << bit) - 1) & i) == R && (cif(i, bit) == 1)) a.emplace_back(i);
send(a);
t = wait()[0];
R |= (t << bit);
}
return pii{L, R};
}
if(lol >= 30 && H >= 2) {
for(int i = 0; i < 10; i++) {
vector<int> a, b;
for(int j = 1; j <= 1000; j++)
(!(j & (1 << i))? a : b).emplace_back(j);
send(a);
send(b);
}
auto T = wait();
vector<int> uncertain;
int common = 0;
for(int i = 0, bit = 0; i < sz(T); bit++, i += 2) {
if(T[i] && T[i + 1]) uncertain.emplace_back(bit);
else common |= (T[i]? 0 : (1 << bit));
}
if(sz(uncertain) == 0) return pii{common, common};
if(sz(uncertain) == 1) return pii{common, common | (1 << uncertain[0])};
for(int i = 1; i < sz(uncertain); i++) {
vector<int> a;
for(int j = 1; j <= 1000; j++) {
if(cif(j, uncertain[i]) != cif(j, uncertain[i - 1])) a.emplace_back(j);
}
send(a);
}
T = wait();
int L = common, R = common | (1 << uncertain[0]);
int how = 0;
for(int i = 0; i < sz(T); i++) {
how ^= T[i];
L |= (how << uncertain[i + 1]);
R |= ((1 ^ how) << uncertain[i + 1]);
}
return pii{L, R};
}
else {
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
vector<int> p(1001), inv = p;
iota(all(p), 0);
shuffle(1 + all(p), rng);
for(int i = 1; i < sz(p); i++) inv[p[i]] = i;
for(int i = 0; i < 10; i++) {
vector<int> a, b;
for(int j = 1; j <= 1000; j++)
(!(j & (1 << i))? a : b).emplace_back(p[j]);
send(a);
send(b);
}
for(int i = 0; i < 10; i++) {
for(int t = i + 1, C = 0; C < 5 && t < 10; C++, t++) {
vector<int> a;
for(int j = 1; j <= 1000; j++) {
if(cif(j, i) != cif(j, t)) a.emplace_back(p[j]);
}
send(a);
}
}
auto T = wait();
vector<int> uncertain;
int common = 0;
for(int i = 0, bit = 0; bit < 10; bit++, i += 2) {
if(T[i] && T[i + 1]) uncertain.emplace_back(bit);
else common |= (T[i]? 0 : (1 << bit));
}
if(sz(uncertain) == 0) return pii{p[common], p[common]};
if(sz(uncertain) == 1) return pii{p[common], p[common | (1 << uncertain[0])]};
int mat[12][12];
int ptr = 20;
for(int i = 0; i < 10; i++) {
for(int t = i + 1, C = 0; C < 5 && t < 10; C++, t++) {
mat[i][t] = T[ptr++];
}
}
int L = common, R = common | (1 << uncertain[0]);
int how = 0;
for(int i = 1; i < sz(uncertain); i++) {
how ^= mat[uncertain[i - 1]][uncertain[i]];
L |= (how << uncertain[i]);
R |= ((1 ^ how) << uncertain[i]);
}
cerr << common << '\n';
for(auto x: uncertain) cerr << x << ' ';
cerr << '\n';
return pii{p[L], p[R]};
}
}