Submission #831994

#TimeUsernameProblemLanguageResultExecution timeMemory
831994dxz05Prisoner Challenge (IOI22_prison)C++17
80 / 100
9 ms980 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 if (pd == 2){ 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){
      |                                 ~~~~~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...