#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
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 time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Runtime error |
3 ms |
632 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
3 |
Runtime error |
3 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
4 |
Runtime error |
3 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
5 |
Incorrect |
5 ms |
504 KB |
Output isn't correct |
6 |
Runtime error |
3 ms |
612 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
7 |
Incorrect |
9 ms |
632 KB |
Output isn't correct |
8 |
Runtime error |
3 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
9 |
Incorrect |
16 ms |
760 KB |
Output isn't correct |
10 |
Incorrect |
16 ms |
900 KB |
Output isn't correct |
11 |
Incorrect |
21 ms |
888 KB |
Output isn't correct |
12 |
Runtime error |
3 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
13 |
Runtime error |
3 ms |
536 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
14 |
Incorrect |
828 ms |
2232 KB |
Output isn't correct |
15 |
Runtime error |
3 ms |
508 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
16 |
Runtime error |
3 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
17 |
Runtime error |
3 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
18 |
Incorrect |
1579 ms |
2680 KB |
Output isn't correct |
19 |
Runtime error |
3 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
20 |
Runtime error |
3 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |