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 <bits/stdc++.h>
using namespace std;
#define mp make_pair
using ii = pair<int, int>;
vector<vector<int> > devise_strategy(int N) {
int b = 13;
int base = 2;
int x = (base + 1) * (b + 1) - 1;
vector<vector<int> > s(x + 1, vector<int>(N + 1));
auto unpack = [&](int v) {
int b_bit = v / (base + 1), state = v % (base + 1);
return mp(b - b_bit, state);
};
auto pack = [&](int bit, int state) {
int tmp = (b - bit) * (base + 1) + state;
assert(0 <= tmp && tmp <= x);
return tmp;
};
auto get_digit = [&](int num, int pos) {
while (pos--) {
num /= base;
}
return num % base;
};
for (int i = 0; i <= x; i++) {
auto [bit, state] = unpack(i);
if (state == 0) {
s[i][0] = 0;
for (int j = 1; j <= N; j++) {
// find digit at position bit of j
int digit = get_digit(j, bit);
assert(0 <= digit && digit < base);
// write (bit, digit + 1)
s[i][j] = pack(bit, digit + 1);
}
} else {
s[i][0] = 1;
for (int j = 1; j <= N; j++) {
// find digit at position bit of j
int digit = get_digit(j, bit);
if (digit == state - 1) {
if (bit == 0) {
s[i][j] = 0;
} else {
// write (bit - 1, 0)
s[i][j] = pack(bit - 1, 0);
}
} else if (digit > state - 1) {
s[i][j] = -1;
} else {
s[i][j] = -2;
}
}
}
}
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... |