이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |