Submission #1090311

#TimeUsernameProblemLanguageResultExecution timeMemory
1090311vjudge1Sailing Race (CEOI12_race)C++14
40 / 100
434 ms2484 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, k, i, j, l, r, d, t; cin >> n >> k; vector<vector<int> > le(n), ri(n); vector<vector<bool> > w(n); for (i = 0; i < n; i++) { le[i].resize(n); ri[i].resize(n); w[i].resize(n); for (j = 0; j < n; j++) w[i][j] = 0; while (1) { cin >> d; if (!d) break; w[i][d - 1] = 1; } } for (i = 0; i < n; i++) { for (l = 0; l < n; l++) { r = (l + i) % n; le[l][r] = ri[l][r] = 0; for (j = 1; j < i; j++) { d = (l + j) % n; t = max(ri[l][d], le[d][r]) + 1; if (w[l][d]) le[l][r] = max(le[l][r], t); if (w[r][d]) ri[l][r] = max(ri[l][r], t); } } } t = r = 0; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { l = 0; if (w[i][j]) l = max(ri[i][j], le[j][i]) + 1; if (l > t) { t = l; r = i; } } } cout << t << "\n" << r + 1; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...