Submission #635342

#TimeUsernameProblemLanguageResultExecution timeMemory
635342marvinthangPrisoner Challenge (IOI22_prison)C++17
Compilation error
0 ms0 KiB
/************************************* * author: marvinthang * * created: 25.08.2022 20:38:19 * *************************************/ #include <bits/stdc++.h> using namespace std; #define fi first #define se second #define div ___div #define left ___left #define right ___right #define TIME (1.0 * clock() / CLOCKS_PER_SEC) #define MASK(i) (1LL << (i)) #define FULL(i) (MASK(i) - 1) #define BIT(x, i) ((x) >> (i) & 1) #define __builtin_popcount __builtin_popcountll #define scan_op(...) istream & operator >> (istream &in, __VA_ARGS__ &u) #define print_op(...) ostream & operator << (ostream &out, const __VA_ARGS__ &u) #define file(name) if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); } template <class T> scan_op(vector <T>) { for (size_t i = 0; i < u.size(); ++i) in >> u[i]; return in; } template <class T> print_op(vector <T>) { out << '{'; for (size_t i = 0; i + 1 < u.size(); ++i) out << u[i] << ", "; if (!u.empty()) out << u.back(); return out << '}'; } template <class U, class V> scan_op(pair <U, V>) { return in >> u.fi >> u.se; } template <class U, class V> print_op(pair <U, V>) { return out << '(' << u.fi << ", " << u.se << ')'; } const double PI = 3.1415926535897932384626433832795; // acos(-1.0); atan(-1.0); const int dir[] = {1, 0, -1, 0, 1, 1, -1, -1, 1}; // {2, 1, -2, -1, -2, 1, 2, -1, 2}; const int NUM_BIT = 8; const int NUM_STATE = NUM_BIT * 3 - 1; const int p3[] = {1, 3, 9, 27, 81, 243, 729, 2187, 6561}; int get_bit(int n, int bit) { if (bit < 0) return 0; return (n % p3[bit + 1]) / p3[bit]; } pair <int, int> decode(int code) { --code; if (code < 0) return make_pair(0, 0); return make_pair(NUM_BIT - code / 3 - 1, code % 3); } int encode(int bit, int t) { if (bit < 0) return 0; return (NUM_BIT - bit - 1) * 3 + t + 1; } vector <vector <int>> devise_strategy(int n) { vector <vector <int>> res(NUM_STATE, vector<int> (n + 1, 0)); // case 0 res[0][0] = 0; for (int i = 1; i <= n; ++i) res[0][i] = encode(NUM_BIT - 1, get_bit(i, NUM_BIT - 1)); // case 1 -> 18 for (int bit = 1; bit < NUM_BIT; ++bit) for (int t = 0; t < 3; ++t) { int state = encode(bit, t); int cur = bit & 1; int pre = cur ^ 1; res[state][0] = cur; for (int i = 1; i <= n; ++i) { int pre_bit = t; int cur_bit = get_bit(i, bit); if (pre_bit < cur_bit) res[state][i] = -1 - pre; else if (pre_bit > cur_bit) res[state][i] = -1 - cur; else { if (bit > 2) res[state][i] = encode(bit - 1, get_bit(i, bit - 1)); else { int r = i % 9; if (r == 0) res[state][i] = -1 - cur; else if (r == 8) res[state][i] = -1 - pre; else if (r <= 4) res[state][i] = 19; else res[state][i] = 20; } } } } // case 19, 20 for (int state: {19, 20}) { int cur = 1, pre = 0; res[state][0] = cur; for (int i = 1; i <= n; ++i) { int r = i % 9; if (state == 19) { if (r <= 1) res[state][i] = -1 - cur; else if (r >= 4) res[state][i] = -1 - pre; else res[state][i] = 21; } else { if (r <= 5) res[state][i] = -1 - cur; else if (r >= 7) res[state][i] = -1 - pre; else res[state][i] = 21; } } } // case 21 int cur = 0, last = 1; res[21][0] = cur; for (int i = 1; i <= n; ++i) { int r = i % 9; if (r <= 4) { if (r <= 2) res[21][i] = -1 - cur; else res[21][i] = -1 - pre; } else { if (r <= 6) res[21][i] = -1 - cur; else res[21][i] = -1 - pre; } } return res; }

Compilation message (stderr)

prison.cpp: In function 'std::vector<std::vector<int> > devise_strategy(int)':
prison.cpp:105:27: error: 'pre' was not declared in this scope
  105 |    else res[21][i] = -1 - pre;
      |                           ^~~
prison.cpp:108:27: error: 'pre' was not declared in this scope
  108 |    else res[21][i] = -1 - pre;
      |                           ^~~
prison.cpp:99:15: warning: unused variable 'last' [-Wunused-variable]
   99 |  int cur = 0, last = 1;
      |               ^~~~