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 <bits/stdc++.h>
#define ll int
#define ln "\n"
using namespace std;
ll code(ll x, ll i){
string s = "";
while (x){
s+=to_string(x%3);
x/=3;
}
while (s.length()<8) s+='0';
reverse(s.begin(), s.end());
return s[i]-'0';
}
std::vector<std::vector<int>> devise_strategy(int N) {
vector<vector<ll>> ans(25, vector<ll>(N+1));
for (ll i=1; i<=N; i++){
ll cd=code(i, 0);
ans[0][i]=cd*8+1;
}
for (ll x=1; x<=24; x++){
if (x%2){
ans[x][0]=1;
ll pos=(x-1)%8, val=(x-1)/8;
for (ll i=1; i<=N; i++){
ll cd = code(i, pos);
if (cd>val) ans[x][i]=-1;
else if (cd<val) ans[x][i]=-2;
else {
if (pos+1==8) ans[x][i]=0;
else ans[x][i]=code(i, pos+1)*8+pos+2;
}
}
}else{
ans[x][0]=0;
ll pos=(x-1)%8, val=(x-1)/8;
for (ll i=1; i<=N; i++){
ll cd = code(i, pos);
if (cd>val) ans[x][i]=-2;
else if (cd<val) ans[x][i]=-1;
else {
if (pos+1==8) ans[x][i]=0;
else ans[x][i]=code(i, pos+1)*8+pos+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... |