Submission #132235

#TimeUsernameProblemLanguageResultExecution timeMemory
132235amoo_safarSailing Race (CEOI12_race)C++14
0 / 100
1579 ms2680 KiB
#include<bits/stdc++.h> #define pb push_back using namespace std; typedef long long ll; const int Maxn = 5e2 + 10; bool G[Maxn][Maxn]; int n, dp[Maxn][Maxn][2]; int nxt(int y){ return (y + 1) % n; } int prev(int y){ return (y - 1 + n) % n; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int k; cin >> n >> k; if(k == 1){ cout << G[5000][5000]; return 0; } int adj; for(int i = 0; i < n; i++){ while(true){ cin >> adj; adj --; if(adj == -1) break; G[i][adj] = true; } } for(int l = 1; l <= n; l++){ for(int i = 0; i < n; i++){ int j = (i + l) % n; dp[i][j][0] = 1; for(int k = nxt(i); k != j; k = nxt(k)){ if(G[i][k]) dp[i][j][0] = max( dp[i][j][0], max(dp[k][j][0], dp[k][i][1]) + 1); } dp[i][j][1] = 1; for(int k = prev(i); k != j; k = prev(k)){ if(G[i][k]) dp[i][j][1] = max( dp[i][j][1], max(dp[k][j][1], dp[k][i][0]) + 1); } } } int ans = 0, st = 0; for(int i = 0; i < n; i++){ ans = max(ans, dp[i][i][0]); if(ans == dp[i][i][0]) st = i; } cout << ans << '\n' << st + 1 << '\n'; return 0; } /* 7 1 5 0 5 0 7 0 3 0 4 0 4 3 0 2 1 0 */

Compilation message (stderr)

race.cpp: In function 'int main()':
race.cpp:27:23: warning: array subscript is above array bounds [-Warray-bounds]
   cout << G[5000][5000];
           ~~~~~~~~~~~~^
race.cpp:27:17: warning: array subscript is above array bounds [-Warray-bounds]
   cout << G[5000][5000];
           ~~~~~~^
#Verdict Execution timeMemoryGrader output
Fetching results...