This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |