#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1010;
vector<int> grafo[MAXN];
int dp[MAXN][MAXN],N,K;
int solve(int i,int j){
if(dp[i][j] != -1) return dp[i][j];
if(i == j) return dp[i][j] = 0;
int best = 0;
for(int k : grafo[i]){
if(k > i && k <= j){
best = max(best, solve(k,j) + 1 );
}
}
return dp[i][j] = best;
}
void adiciona(int i,int j){
grafo[i].push_back(j);
grafo[i].push_back(j+N);
grafo[i+N].push_back(j);
grafo[i+N].push_back(j+N);
}
int main(){
memset(dp,-1,sizeof(dp));
cin >> N >> K;
assert(K != 1);
for(int i = 1;i<=N;i++){
int x;
while(cin >> x && x){
adiciona(i,x);
}
}
int best = -1,ans = 0;
for(int i = 1,j = N;i<=N;i++,j++){
int candidate = solve(i,j);
if(candidate > best){
best = candidate;
ans = i;
}
}
cout << best << endl << ans << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4472 KB |
Output is correct |
2 |
Runtime error |
11 ms |
8696 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
3 |
Runtime error |
12 ms |
8820 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
4 |
Runtime error |
15 ms |
8940 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
5 |
Incorrect |
8 ms |
9004 KB |
Output isn't correct |
6 |
Runtime error |
14 ms |
9048 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
7 |
Incorrect |
10 ms |
9048 KB |
Output isn't correct |
8 |
Runtime error |
15 ms |
9048 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
9 |
Incorrect |
8 ms |
9096 KB |
Output isn't correct |
10 |
Correct |
13 ms |
9236 KB |
Output is correct |
11 |
Incorrect |
10 ms |
9236 KB |
Output isn't correct |
12 |
Runtime error |
13 ms |
9236 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
13 |
Runtime error |
12 ms |
9236 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
14 |
Incorrect |
31 ms |
9424 KB |
Output isn't correct |
15 |
Runtime error |
13 ms |
9424 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
16 |
Runtime error |
13 ms |
9424 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
17 |
Runtime error |
14 ms |
9424 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
18 |
Incorrect |
48 ms |
9532 KB |
Output isn't correct |
19 |
Runtime error |
14 ms |
9532 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
20 |
Runtime error |
14 ms |
9532 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |