#include "prison.h"
#include <bits/stdc++.h>
using namespace std;
const int X = 23;
const int M = 8;
int p[M];
int check(int x, int k) {
return ((x / p[k]) % 3);
}
vector<vector<int>> devise_strategy(int N) {
p[0] = 1;
for (int i = 1; i < M; ++i) p[i] = p[i - 1] * 3;
vector<vector<int>> ret(X, vector<int> (N + 1));
ret[0][0] = 0;
for (int i = 1; i <= N; ++i) {
ret[0][i] = 7 * 3 - 1 + check(i, 7);
}
for (int i = 1; i < X; ++i) {
int bit = (i + 1) / 3;
int state = (i + 1) % 3;
if (bit == 0) {
state = 1;
}
if (bit % 2) {
ret[i][0] = 1;//identify B
for (int j = 1; j <= N; ++j) {
if (state < check(j, bit)) {
ret[i][j] = -1;
} else if (state > check(j, bit)) {
ret[i][j] = -2;
} else {
if (bit > 1) {
ret[i][j] = (bit - 1) * 3 - 1 + check(j, bit - 1);
} else {
int nxState = check(j, bit - 1);
if (nxState == 2) {//B is bigger
ret[i][j] = -1;
} else if (nxState == 0) {
ret[i][j] = -2;
} else {
ret[i][j] = 1;
}
}
}
}
} else {
ret[i][0] = 0;
for (int j = 1; j <= N; ++j) {
if (state < check(j, bit)) {
ret[i][j] = -2;
} else if (state > check(j, bit)) {
ret[i][j] = -1;
} else if (bit > 0) {
ret[i][j] = (bit - 1) * 3 - 1 + check(j, bit - 1);
}
}
}
}
return ret;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Partially correct |
0 ms |
348 KB |
Output is partially correct |
3 |
Partially correct |
0 ms |
344 KB |
Output is partially correct |
4 |
Partially correct |
5 ms |
600 KB |
Output is partially correct |
5 |
Partially correct |
8 ms |
856 KB |
Output is partially correct |
6 |
Partially correct |
13 ms |
1112 KB |
Output is partially correct |
7 |
Partially correct |
9 ms |
1112 KB |
Output is partially correct |
8 |
Partially correct |
0 ms |
344 KB |
Output is partially correct |
9 |
Partially correct |
1 ms |
344 KB |
Output is partially correct |
10 |
Partially correct |
1 ms |
344 KB |
Output is partially correct |
11 |
Partially correct |
5 ms |
600 KB |
Output is partially correct |
12 |
Partially correct |
8 ms |
856 KB |
Output is partially correct |