이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "prison.h"
#include <bits/stdc++.h>
using namespace std;
int log2(int v) {
int r = 0;
while (v >>= 1) {
r++;
}
return r;
}
int pack(int pos, int b, int ab) {
return (pos << 3) | ((b & 1) << 2) | ((ab & 1) << 1) | 0b1;
}
vector<vector<int>> devise_strategy(int N) {
int nbits = log2(N);
int x = (nbits << 3) | 0b111;
vector<vector<int>> s(x + 1, vector<int>(N + 1));
for (int pos = nbits; pos >= 0; --pos) {
// previously inspected bit
for (int b = 0; b <= 1; ++b) {
// ab = 0 => bag a
// ab = 1 => bag b
// previously inspected
for (int ab = 0; ab <= 1; ++ab) {
int i = pack(pos, b, ab);
// Inspect the other bag next
s[i][0] = !ab;
for (int v = 1; v <= N; ++v) {
// printf("pos: %d b: %d ab: %d v: %d\n", pos, b, ab, v);
bool selfset = (v >> pos) & 1;
if (selfset && !b) {
// if the bag we previously inspected did not have bit at pos set,
// but we do
s[i][v] = ab ? -2 : -1;
} else if (!selfset && b) {
// vice-versa
s[i][v] = ab ? -1 : -2;
} else if (pos != 0) {
// move to a lesser significant bit
s[i][v] = pack(pos - 1, selfset, !ab);
}
// printf(" s[%d][%d] = %d\n", i, v, s[i][v]);
}
}
}
}
// whiteboard is always 0 initially, so inspect A
s[0][0] = 0;
for (int v = 1; v <= N; ++v) {
bool selfset = (v >> nbits) & 1;
s[0][v] = pack(nbits, selfset, 0);
}
return s;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |