Submission #626931

#TimeUsernameProblemLanguageResultExecution timeMemory
626931Lam_lai_cuoc_doiPrisoner Challenge (IOI22_prison)C++17
51.50 / 100
63 ms98292 KiB
#include "prison.h" #include <vector> #include <algorithm> using namespace std; constexpr int N = 5005; vector<vector<int>> a; int n; bool ck[N]; #define bit(i, x) (((x) >> (i)) & 1) void Recursive(int v) { if (ck[v]) return; ck[v] = 1; if (v == 0) { a[v][0] = 0; for (int i = 1; i <= n; ++i) a[v][i] = 12 + (bit(12, i) << 4) + 1; for (int i = 1; i <= n; ++i) if (a[v][i] > 0) Recursive(a[v][i]); return; } --v; int number = v & 15; int state = bit(4, v); ++v; if (!(number & 1)) { a[v][0] = 1; for (int i = 1; i <= n; ++i) if (bit(number, i) < state) a[v][i] = -2; else if (bit(number, i) > state) a[v][i] = -1; else a[v][i] = number + (bit(number - 1, i) << 4); for (int i = 1; i <= n; ++i) if (a[v][i] > 0) Recursive(a[v][i]); } else { a[v][0] = 0; for (int i = 1; i <= n; ++i) if (bit(number, i) < state) a[v][i] = -1; else if (bit(number, i) > state) a[v][i] = -2; else a[v][i] = number + (bit(number - 1, i) << 4); for (int i = 1; i <= n; ++i) if (a[v][i] > 0) Recursive(a[v][i]); } } std::vector<std::vector<int>> devise_strategy(int m) { n = m; a.resize(5000, vector<int>(n + 1, 0)); Recursive(0); while (!ck[a.size() - 1]) a.pop_back(); return a; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...