Submission #1090333

#TimeUsernameProblemLanguageResultExecution timeMemory
1090333vjudge1Sailing Race (CEOI12_race)C++17
5 / 100
385 ms3672 KiB
#include <bits/stdc++.h> #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() //#define int long long using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; const int mod = 1e9 + 7; const int LOG = 20; const int maxn = 1e5 + 5; int dp[505][505][2], mat[505][505]; signed main() { int n, k; cin >> n >> k; for(int i=1; i<=n; i++) { int x; while(cin >> x) { if(!x) break; mat[i-1][x-1] = 1; } } for(int len=1; len<=n; len++) { for(int i=0; i<n; i++) { int j = (i + len - 1) % n; if(mat[i][j]) dp[i][j][0] = max(dp[i][j][0], dp[(i+1)%n][j][1] + 1); if(mat[j][i]) dp[i][j][1] = max(dp[i][j][1], dp[i][(i+len-2)%n][0] + 1); for(int k=i+1; k<i+len-1; k++) { int x = k % n; dp[i][j][0] = max(dp[i][j][0], dp[i][x][0]); dp[i][j][1] = max(dp[i][j][1], dp[x][j][1]); if(mat[i][x]) dp[i][j][0] = max(dp[i][j][0], dp[x][j][0] + 1); if(mat[j][x]) dp[i][j][1] = max(dp[i][j][1], dp[i][x][1] + 1); } } } int ans = -1, ans2 = 0; for(int i=0; i<n; i++) { for(int j=0; j<n; j++) { if(dp[i][j][0] > ans) { ans = dp[i][j][0]; ans2 = i; } if(dp[i][j][1] > ans) { ans = dp[i][j][1]; ans2 = j; } } } cout << ans + 1 << '\n' << ans2 + 1 << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...