Submission #679072

#TimeUsernameProblemLanguageResultExecution timeMemory
679072vjudge1Sailing Race (CEOI12_race)C++17
40 / 100
225 ms6668 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 1005; int n, k, dp[MAXN][MAXN][2][2], ans, ans_node; vector<int> adj[MAXN]; bool bio[MAXN]; int cur_i, cur_j, cur_b; int main(){ cin >> n >> k; for(int i = 0; i < n; ++i){ int x; cin >> x; while(x){ --x; adj[i].push_back(x); cin >> x; } } for(int off = 1; off < n; ++off){ for(int i = 0; i < n; ++i){ int j = (i + off) % n; for(int x : adj[i]){ if((i < j && i < x && x <= j) || (i > j && (i < x || x <= j))){ dp[i][j][0][0] = max(dp[i][j][0][0], max(dp[(i + 1) % n][x][1][1], dp[x][j][0][0]) + 1); dp[i][j][0][1] = max(dp[i][j][0][1], max(dp[(i + 1) % n][x][1][1], dp[x][j][0][1]) + 1); } } for(int x : adj[j]){ if((i < j && i <= x && x < j) || (i > j && (i <= x || x < j))){ dp[i][j][1][0] = max(dp[i][j][1][0], max(dp[i][x][1][0], dp[x][(j - 1 + n) % n][0][1]) + 1); dp[i][j][1][1] = max(dp[i][j][1][1], max(dp[i][x][1][1], dp[x][(j - 1 + n) % n][0][1]) + 1); } } ans = max(ans, dp[i][j][0][0]); ans = max(ans, dp[i][j][1][0]); if(dp[i][j][0][0] == ans){ ans_node = i; } if(dp[i][j][1][0] == ans){ ans_node = j; } } } cout << ans << "\n" << ans_node + 1; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...