제출 #629032

#제출 시각아이디문제언어결과실행 시간메모리
629032Lam_lai_cuoc_doi죄수들의 도전 (IOI22_prison)C++17
0 / 100
1 ms548 KiB
#include "prison.h" #include <vector> #include <algorithm> using namespace std; constexpr int N = 5005; vector<vector<int>> a; int n, maxbit; 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] = maxbit - 1 + (bit(maxbit, i) * maxbit) + 1; for (int i = 1; i <= n; ++i) if (a[v][i] > 0) Recursive(a[v][i]); return; } --v; int number, state; if (v >= maxbit) { state = 1; number = v - maxbit; } else { state = 0; number = v; } ++number; ++v; if ((number & 1) == (maxbit & 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 { if (number == 1) { if (bit(0, i)) a[v][i] = -1; else a[v][i] = -2; } a[v][i] = number - 1 + (bit(number - 1, i) * maxbit); } 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 { if (number == 1) { if (bit(0, i)) a[v][i] = -2; else a[v][i] = -1; } else a[v][i] = number - 1 + (bit(number - 1, i) * maxbit); } 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; maxbit = __lg(n); 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...