# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
852526 | grossly_overconfident | Prisoner Challenge (IOI22_prison) | C++17 | 0 ms | 0 KiB |
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;
string convert_binary(int j){
string s = "";
for (int i = 1; i <= 13; ++i){
int p = pow(2, i), p2 = pow(2, i - 1) - 1;
if (j % p > p2){
s += '1';
}
else{
s += '0';
}
}
reverse(s.begin(), s.end());
return s;
}
vector<vector<int>> devise_strategy(int n){
int x = 26;
vector<vector<int>> out(x, vector<int>(n + 1));
for (int i = 0; i < x; ++i){
if ((i + 1) % 4 != 0 && ((i + 1) % 4) - 1 != 0){
out[i][0] = 1;
}
for (int j = 1; j <= n; ++j){
if (i == 0){
if (convert_binary(j)[0] == '1'){
out[i][j] = 2;
}
else{
out[i][j] = 1;
}
}
else{
if (out[i][0] == 1){
int b = convert_binary(j);
int ind = 0;
int k = i;
while (k > 2){
k -= 4;
ind += 1;
}
char c = k + 47;
if (b[ind] > c){
out[i][j] = -1;
}
else if (b[ind] < c){
out[i][j] = -2;
}
else if (b[ind + 1] == '0'){
k = i + 1;
while (k % 2 == 0){
k += 1;
}
out[i][j] = k;
}
else{
k = i + 1;
while (k % 2 == 1){
k += 1;
}
out[i][j] = k;
}
}
else {
int a = convert_binary(j);
int ind = 0;
int k = i;
while (k > 2){
k -= 4;
ind += 1;
}
char c = k + 47;
if (a[ind] > c){
out[i][j] = -2;
}
else if (b[ind] < c){
out[i][j] = -1;
}
else if (a[ind + 1] == '0'){
k = i + 1;
while (k % 2 == 0){
k += 1;
}
out[i][j] = k;
}
else{
k = i + 1;
while (k % 2 == 1){
k += 1;
}
out[i][j] = k;
}
}
}
}
}
return out;
}
int main(){
int n;
cin >> n;
cout << convert_binary(n);
}