#include "prison.h"
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
//#define int long long
#define pii pair<int,int>
#define vi vector<int>
#define ff first
#define ss second
#define sp << " " <<
#define all(x) x.begin(),x.end()
#define big(x) ((int)(x.size()))
using namespace std;
const int MOD = 1e9+7, LIM = 1e6+1, inf = 2e9;
int bit(int x,int b) {
while (b--) x/=3;
return x%3;
}
std::vector<std::vector<int>> devise_strategy(int N) {
const int x = 22;
vector<vi> ans(x+1,vi(N+1,0));
ans[0][0] = 1;
for (int j = 1;j<=N;j++) ans[0][j] = 3*7+bit(j,7)-1;
for (int i=x;i>=2;i--) {
int idx = (i+1)/3;
int v = (i+1)%3;
ans[i][0] = 1-idx%2;
for (int j = 1;j<=N;j++) {
if (bit(j,idx) != v) {
if (bit(j,idx) < v) {
if (idx%2) ans[i][j] = -1;
else ans[i][j] = -2;
}
else {
if (idx%2) ans[i][j] = -2;
else ans[i][j] = -1;
}
}
else {
if (idx) {
if (idx == 1) {
int vv = bit(j,idx-1);
if (vv == 0) {
if (idx%2) ans[i][j] = -1;
else ans[i][j] = -2;
}
else if (vv == 2) {
if (idx%2) ans[i][j] = -2;
else ans[i][j] = -1;
}
else ans[i][j] = 1;
}
else {
ans[i][j] = 3*(idx-1)+bit(j,idx-1)-1;
}
}
else ans[i][j] = 0;
}
}
}
ans[1][0] = 1;
for (int j=1;j<=N;j++) {
int v = bit(j,0);
int idx = 0;
if (v > 1) ans[1][j] = -1;
else if (v == 1) ans[1][j] = 0;
else ans[1][j] = -2;
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |