Submission #831993

#TimeUsernameProblemLanguageResultExecution timeMemory
831993dxz05Prisoner Challenge (IOI22_prison)C++17
Compilation error
0 ms0 KiB
#include "prison.h" #include <bits/stdc++.h> using namespace std; int get(int num, int pos, int base){ while (pos--) num /= base; return num % base; } int state[20][10]; pair<int, int> meaning[200]; vector<vector<int>> devise_strategy(int N) { const int X = 22; vector<vector<int>> s(X + 1, vector<int>(N + 1, 0)); state[0][1] = 1; meaning[1] = make_pair(0, 1); int nxt = 2; for (int i = 1; i <= 7; i++){ for (int j = 0; j < 3; j++){ meaning[nxt] = make_pair(i, j); state[i][j] = nxt++; } } s[0][0] = 1; for (int i = 1; i <= N; i++){ s[0][i] = state[7][get(i, 7, 3)]; } for (int i = 1; i <= X; i++){ auto [b, r] = meaning[i]; int bag = (7 - b) % 2; s[i][0] = bag; for (int j = 1; j <= N; j++){ int d = get(j, b, 3); if (d < r || b == 0 && d == 0){ s[i][j] = (bag == 0 ? -1 : -2); } else if (d > r || b == 0 && d == 2){ s[i][j] = (bag == 0 ? -2 : -1); } else if (b > 0){ int pd = get(j, b - 1, 3); if (b == 1){ if (pd == 0){ s[i][j] = (bag == 0 ? -1 : -2); } else { s[i][j] = (bag == 0 ? -2 : -1); } else { s[i][j] = state[0][1]; } } else { s[i][j] = state[b - 1][pd]; } } } } return s; }

Compilation message (stderr)

prison.cpp: In function 'std::vector<std::vector<int> > devise_strategy(int)':
prison.cpp:45:33: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   45 |             if (d < r || b == 0 && d == 0){
      |                          ~~~~~~~^~~~~~~~~
prison.cpp:47:40: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   47 |             } else if (d > r || b == 0 && d == 2){
      |                                 ~~~~~~~^~~~~~~~~
prison.cpp:57:23: error: expected '}' before 'else'
   57 |                     } else {
      |                       ^~~~
prison.cpp:52:28: note: to match this '{'
   52 |                 if (b == 1){
      |                            ^
prison.cpp:61:44: error: 'pd' was not declared in this scope; did you mean 'd'?
   61 |                     s[i][j] = state[b - 1][pd];
      |                                            ^~
      |                                            d
prison.cpp:66:5: warning: no return statement in function returning non-void [-Wreturn-type]
   66 |     }
      |     ^
prison.cpp: At global scope:
prison.cpp:68:5: error: expected unqualified-id before 'return'
   68 |     return s;
      |     ^~~~~~
prison.cpp:69:1: error: expected declaration before '}' token
   69 | }
      | ^