Submission #1010409

#TimeUsernameProblemLanguageResultExecution timeMemory
1010409sleepntsheepSeptember (APIO24_september)C++17
100 / 100
147 ms12820 KiB
#include "september.h" #include <algorithm> #include <vector> #include <array> int solve(int N, int M, std::vector<int> P/* F is patriarchy ! */, std::vector<std::vector<int>> S) { using i5 = std::array<int, 5>; std::vector<int> vis(N); std::vector<std::vector<int> > g(N); std::vector<std::vector<int> > SI(M, std::vector<int>(N)); i5 at {}, at2 {}, at3; int K = 0, i, j; for (i = 1; i < N; ++i) g[P[i]].push_back(i); for (i = 0; i < M; ++i) for (j = 0; j < N - 1; ++j) SI[i][S[i][j]] = j; auto dfs = [&](auto &&dfs, int u) -> void { if (vis[u]) return; vis[u] = 1; for (int i = 0; i < M; ++i) at2[i] = std::max(at2[i], SI[i][u] + 1); for (auto v : g[u]) dfs(dfs, v); }; for (; *std::min_element(at.begin(), at.begin() + M) < N - 1; ++K) { for (i = 0; i < M; ++i) at2[i] = std::min(N - 1, at[i] + 1); while (at != at2) { at3 = at2; for (i = 0; i < M; ++i) for (j = at[i]; j < at2[i]; ++j) dfs(dfs, S[i][j]); at = at3; } } return K; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...