#include "prison.h"
#include <bits/stdc++.h>
using namespace std;
int back(int response, int bagN){
int val = response >> 3;
int index = response % 8;
int nInt = (bagN >> (7 - index)) % 4;
if(val != nInt){
return val > nInt ? -1 : -2; //knows answer (might be opposite)
}
//get index + 1 bit
int newIndex = index + 1;
string nIndex = to_string(newIndex);
while(nIndex.size() < 3){
nIndex = "0" + nIndex;
}
string baseThree = "";
while(bagN > 0){
baseThree = to_string(bagN % 3) + baseThree;
bagN /= 3;
}
// convert binary string to int
char base3Val = int(newIndex) >= int(baseThree.size()) ? '0' : baseThree[newIndex];
string inBinary = base3Val + nIndex;
string realBinary = "";
bool hasBeenOne = false;
for(int i = 0; i < inBinary.size(); i++){
if(!hasBeenOne){
if(inBinary[i] == '0'){
continue;
}else{
hasBeenOne = true;
}
}
realBinary += inBinary[i];
}
if(realBinary.size() == 0) realBinary = "0";
// int toBinary = stoi(inBinary, nullptr, 2);
int toBinary = 0;
// int toBinary = stoi(realBinary);
int bit = 1;
for(int i = realBinary.size() - 1; i >= 0; i--){
int binaryDigit = realBinary[i] - '0';
toBinary += bit * binaryDigit;
bit *= 2;
}
return toBinary;
}
vector<vector<int>> devise_strategy(int N) {
int X = 23;
vector<vector<int>> ans;
for(int i = 0; i <= X; i++){
vector<int> row(N + 1);
row[0] = i % 2;
for(int j = 1; j <= N; j++){
row[j] = back(i, j);
}
ans.push_back(row);
}
return ans;
}
// #include "grader.cpp"
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |