Submission #852526

#TimeUsernameProblemLanguageResultExecution timeMemory
852526grossly_overconfidentPrisoner Challenge (IOI22_prison)C++17
Compilation error
0 ms0 KiB
#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); }

Compilation message (stderr)

prison.cpp: In function 'std::vector<std::vector<int> > devise_strategy(int)':
prison.cpp:39:43: error: cannot convert 'std::string' {aka 'std::__cxx11::basic_string<char>'} to 'int' in initialization
   39 |                     int b = convert_binary(j);
      |                             ~~~~~~~~~~~~~~^~~
      |                                           |
      |                                           std::string {aka std::__cxx11::basic_string<char>}
prison.cpp:47:26: error: invalid types 'int[int]' for array subscript
   47 |                     if (b[ind] > c){
      |                          ^
prison.cpp:50:31: error: invalid types 'int[int]' for array subscript
   50 |                     else if (b[ind] < c){
      |                               ^
prison.cpp:53:31: error: invalid types 'int[int]' for array subscript
   53 |                     else if (b[ind + 1] == '0'){
      |                               ^
prison.cpp:69:43: error: cannot convert 'std::string' {aka 'std::__cxx11::basic_string<char>'} to 'int' in initialization
   69 |                     int a = convert_binary(j);
      |                             ~~~~~~~~~~~~~~^~~
      |                                           |
      |                                           std::string {aka std::__cxx11::basic_string<char>}
prison.cpp:77:26: error: invalid types 'int[int]' for array subscript
   77 |                     if (a[ind] > c){
      |                          ^
prison.cpp:80:30: error: 'b' was not declared in this scope
   80 |                     else if (b[ind] < c){
      |                              ^
prison.cpp:83:31: error: invalid types 'int[int]' for array subscript
   83 |                     else if (a[ind + 1] == '0'){
      |                               ^