Submission #1035331

#TimeUsernameProblemLanguageResultExecution timeMemory
1035331LaviniaTornaghiSeptember (APIO24_september)C++17
59 / 100
150 ms17332 KiB
#include "september.h" #include <bits/stdc++.h> using namespace std; int solve(int N, int M, vector<int> F, vector<vector<int>> S) { vector<vector<int>> adj(N); for (int i = 1; i < N; i++) adj[F[i]].push_back(i); vector<vector<int>> inv_S(M, vector<int>(N)); for (int i = 0; i < M; i++) { for (int j = 0; j < N - 1; j++) { inv_S[i][S[i][j]] = j; } } vector<vector<bool>> visited(M, vector<bool>(N)); auto dfs = [&](auto &&dfs, int record, int node) -> int { if (visited[record][node]) return -1; visited[record][node] = true; int ans = inv_S[record][node]; for (auto x: adj[node]) ans = max(ans, dfs(dfs, record, x)); return ans; }; int curr_l = 0, k = 0; while (curr_l != N - 1) { k++; int curr_r = curr_l + 1; for (; curr_l < curr_r; curr_l++) { for (int i = 0; i < M; i++) { curr_r = max(curr_r, dfs(dfs, i, S[i][curr_l]) + 1); } } } 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...