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 "cave.h"
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP MP make_pair
#define EB emplace_back
#define V vector
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << "LINE(" << __LINE__ << ") -> " << #x << " is " << (x) << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
const int INF = 1e9 + 7, N = 5005;
int s[N], d[N], done[N], n;
int ask() {
int res = tryCombination(s);
if(res == -1) res = INF;
return res;
}
pi go(int i) { // find the switch that controls door i
vi can;
for(int i = 0; i < n; i++)
if(!done[i])
can.PB(i);
auto inv = [&] (vi& v) {
for(int i:v) {
s[i] ^= 1;
}
};
int x = ask();
assert(x >= i);
while(can.size() > 1) {
int sz = can.size();
vi l, r;
for(int i = 0; i < sz / 2; i++) l.PB(can[i]);
for(int i = sz / 2; i < sz; i++) r.PB(can[i]);
inv(l);
int y = ask();
assert(y >= i);
inv(l);
if((x == i) == (y == i)) { // in r
can = r;
} else { // in l
can = l;
}
}
assert(can.size() == 1);
int id = can[0], state = s[id];
if(x == i) state ^= 1;
return {id, state};
}
void exploreCave(int _n) {
n = _n;
for(int i = 0; i < n; i++) {
pi p = go(i); // {which switch, which state}
s[p.F] = p.S;
d[p.F] = i;
done[p.F] = 1;
}
answer(s, d);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |