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 <iostream>
#include <vector>
using namespace std;
const int max_dig = 7;
int x = 22;
int get_trit(int num, int j){
while(--j>=0)num/=3;
return num%3;
}
int compare(int i, int j){
int d = (i+2) / 3;
int prev_trit = (i+2) % 3;
int prev_pos = max_dig - d + 1;
int cur_trit = get_trit(j, prev_pos);
bool a = d % 2 == 0;
if(prev_trit != cur_trit){
return (a == (cur_trit > prev_trit)) ? -2 : -1;
}
if(i == 22){
return ((cur_trit == 2) == a) ? -2 : -1;
}
int cur_pos = max_dig - d;
int now_trit = get_trit(j, cur_pos);
if(cur_pos == 0){
if(now_trit == 2){
return a ? -2 : -1;
}
if(now_trit == 0){
return a ? -1 : -2;
}
return 22;
}
return 3 * (d + 1) + now_trit - 2;
}
vector<vector<int>> devise_strategy(int n){
vector<vector<int>> ret(x + 1, vector<int>(n+1));
for(int i = 0; i <= x; ++i){
for(int j = 0; j <= n; ++j){
if(j == 0){
ret[i][j] = ((i+2)/3)%2 != 0;
continue;
}
if(i == 0){
int trit = get_trit(j, max_dig);
ret[i][j] = 1 + trit;
continue;
}
ret[i][j] = min(x, compare(i, j));
}
}
ret[0][0] = 0;
return ret;
}
//compare in base 3
//3**8 > 5000
//therefore need 8 trits for info
//start from highest
//open A
//mark value of highest trit (0, 1, 2)
//3 * 7 + 2 = 23
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |