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 <bits/stdc++.h>
using namespace std;
int solve(int a){
if (a == 1){
return 1;
}
if (a == 10){
return 2;
}
if (a == 100){
return 3;
}
if (a == 1000){
return 4;
}
return ceil(log10(a));
}
int find_digit(int a, int i){
return (to_string(a)[i] - 48);
}
vector<vector<int>> devise_strategy(int n){
int x = 100;
vector<vector<int>> out(x, vector<int>(n + 1));
for (int i = 1; i <= n; ++i){
out[0][i] = solve(i);
}
for (int i = 1; i <= 4; ++i){
out[i][0] = 1;
for (int j = 1; j <= n; ++j){
if (solve(j) > i){
out[i][j] = -1;
continue;
}
if (solve(j) < i){
out[i][j] = -2;
continue;
}
out[i][j] = 10 + find_digit(j, 0);
}
}
for (int i = 10; i <= 19; ++i){
out[i][0] = 0;
for (int j = 1; j <= n; ++j){
int k = find_digit(j, 0);
if (k > i - 10){
out[i][j] = -2;
continue;
}
if (k < i - 10){
out[i][j] = -1;
continue;
}
out[i][j] = 20 + find_digit(j, 1);
}
}
for (int i = 20; i <= 29; ++i){
out[i][0] = 1;
for (int j = 1; j <= n; ++j){
int k = find_digit(j, 1);
if (k > i - 20){
out[i][j] = -1;
continue;
}
if (k < i - 20){
out[i][j] = -2;
continue;
}
out[i][j] = 30 + find_digit(j, 2);
}
}
for (int i = 30; i <= 39; ++i){
out[i][0] = 0;
for (int j = 1; j <= n; ++j){
int k = find_digit(j, 2);
if (k > i - 30){
out[i][j] = -2;
continue;
}
if (k < i - 30){
out[i][j] = -1;
continue;
}
out[i][j] = 40 + find_digit(j, 3);
}
}
for (int i = 40; i <= 49; ++i){
out[i][0] = 1;
for (int j = 1; j <= n; ++j){
int k = find_digit(j, 3);
if (k > i - 40){
out[i][j] = -1;
continue;
}
if (k < i - 40){
out[i][j] = -2;
}
}
}
return out;
}
signed maint(){
int a, b;
cin >> a >> b;
int n = 5000;
vector<vector<int>> strats = devise_strategy(n);
int whiteboard = 0;
while (whiteboard >= 0){
if (strats[whiteboard][0] == 0){
whiteboard = strats[whiteboard][a];
}
else{
whiteboard = strats[whiteboard][b];
}
}
cout << whiteboard;
}
Compilation message (stderr)
prison.cpp: In function 'int maint()':
prison.cpp:125:1: warning: no return statement in function returning non-void [-Wreturn-type]
125 | }
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |