# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
628846 | c28dnv9q3 | Prisoner Challenge (IOI22_prison) | C++17 | 16 ms | 1160 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 "prison.h"
#include <vector>
#include <cstdio>
using namespace std;
struct State {
int bitn;
int isset;
};
int N;
int encode(State s) {
int v = (s.bitn << 1) | (s.isset << 0);
// printf("%d %d\n", s.bitn, v);
return v;
}
State decode(int v) {
State s;
s.isset = (v >> 0) & 1;
s.bitn = v >> 1;
return s;
}
vector<vector<int>> devise_strategy(int N) {
::N = N;
int Q = 26;
vector<vector<int>> s(Q+1, vector<int>(N+1));
s[0][0] = 0; // inspect bag A
for (int i = 1; i <= N; i++) {
State p{};
p.bitn = 12;
p.isset = (i & (1 << p.bitn)) ? 1 : 0;
s[0][i] = encode(p);
}
for (int i = 1; i < s.size(); i++) {
// when sees i on board
State pi = decode(i);
int t = 1-(pi.bitn&1);
s[i][0] = t; // inspect bag A/B
for (int j = 1; j <= N; j++) {
// j in bag A/B
bool b = j & (1 << pi.bitn);
if (b && !pi.isset) {
s[i][j] = t ? -1 : -2; // other has less
} else if (!b && pi.isset) {
s[i][j] = t ? -2 : -1; // this has less
} else if (pi.bitn == 0) {
s[i][j] = -1; // shouldn't happen
} else {
State p;
p.bitn = pi.bitn - 1;
p.isset = (j & (1 << p.bitn)) ? 1 : 0;
s[i][j] = encode(p);
if (s[i][j] == 0) {
s[i][j] = t ? -2 : -1; // this has less
}
}
}
}
return s;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |