Submission #668712

#TimeUsernameProblemLanguageResultExecution timeMemory
668712finn__Sailing Race (CEOI12_race)C++17
10 / 100
599 ms6728 KiB
#include <bits/stdc++.h> using namespace std; int main() { size_t n, k; cin >> n >> k; vector<vector<bool>> g(n, vector<bool>(n, 0)); for (size_t i = 0; i < n; i++) { unsigned v; cin >> v; while (v) { g[i][v - 1] = 1; cin >> v; } } vector<vector<unsigned>> c(n, vector<unsigned>(n, 0)), cc(n, vector<unsigned>(n, 0)); unsigned max_length = 0, start = -1; for (size_t l = 2; l < n; l++) { for (size_t i = 0; i < n; i++) { size_t const j = (i + l) % n; for (size_t k = i + 1; k < i + l; k++) { if (g[i][k % n]) cc[i][j] = max(cc[i][j], max(cc[k % n][j], c[k % n][i]) + 1); if (g[j][k % n]) c[j][i] = max(c[j][i], max(cc[k % n][j], c[k % n][i]) + 1); if (g[i][j] && max(c[i][j], cc[i][j]) + 1 > max_length) { max_length = max(c[i][j], cc[i][j]) + 1; start = i + 1; } } } } if (k == 0) { cout << max_length << '\n' << start << '\n'; return 0; } vector<vector<unsigned>> longest(n, vector<unsigned>(n, 0)); for (size_t l = 1; l < n; l++) { for (size_t i = 0; i < n; i++) { size_t const j = (i + l) % n; if (g[i][j]) longest[i][j] = 1; for (size_t k = i + 1; k < i + l; k++) { if (longest[i][k] && longest[k][j]) longest[i][j] = max(longest[i][j], longest[i][k] + longest[k][j]); } } } }
#Verdict Execution timeMemoryGrader output
Fetching results...