/*
dp[node 1][node 2][0/1] = max edges in the range starting at node 1/2 (based on the third dimension)
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i, a, b) for(int i=a; i<b; i++)
#define ffi For(i, 0, N)
#define ffj For(j, 0, N)
#define ffa ffi ffj
#define s <<" "<<
#define c <<" : "<<
#define w cout
#define e endl//"\n"
#define pb push_back
#define mp make_pair
#define a first
#define b second
#define int ll
const int MAXN=500, INF=1000000000000000000;
///500,000,000
int N, K, dp[MAXN][MAXN][2], out, loc;
vector<int> adj[MAXN];
bool in (int x, int y, int z) {
if (y < z) return y < x && x < z;
return x > y || x < z;
}
int solve(int n1, int n2, int at) {
if (dp[n1][n2][at] != -1) return dp[n1][n2][at];
dp[n1][n2][at] = 0;
//w<< n1 s n2 s at<<e;
/// range is n1+1 to n2-1 (n1+1)%N to (n2-1+N)%N
if ((n1+1)%N == n2) {dp[n1][n2][at] = 0; return dp[n1][n2][at];}
if (at == 0) {
/// at n1
for (int i: adj[n1]) if (in(i, n1, n2)) {
dp[n1][n2][0] = max(dp[n1][n2][0], max(solve(n1, i, 1), solve(i, n2, 0))+1);
}
return dp[n1][n2][0];
}
/// at n2
for (int i: adj[n2]) if (in(i, n1, n2)) {
dp[n1][n2][1] = max(dp[n1][n2][1], max(solve(i, n2, 0), solve(n1, i, 1))+1);
}
return dp[n1][n2][1];
}
main() {
//ifstream cin("test.in");
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> N >> K;
ffi {int a; cin >> a; while (a != 0) {adj[i].pb(a-1); cin >> a;}}
ffa dp[i][j][0] = dp[i][j][1] = -1;
ffi solve(i, i, 0);
if (K == 0) ffi{
if (dp[i][i][0] > out) {out = dp[i][i][0]; loc = i+1;}
}
else {
assert(false);
}
//ffa w<< i+1 s j+1 c solve(i, j, 0) s solve(i, j, 1)<<e;
w<< out s loc<<e;
}
Compilation message
race.cpp:50:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main() {
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Runtime error |
4 ms |
892 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
3 |
Runtime error |
3 ms |
960 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
4 |
Runtime error |
4 ms |
1040 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
5 |
Correct |
3 ms |
1144 KB |
Output is correct |
6 |
Runtime error |
4 ms |
1384 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
7 |
Correct |
5 ms |
1508 KB |
Output is correct |
8 |
Runtime error |
5 ms |
1704 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
9 |
Correct |
6 ms |
1756 KB |
Output is correct |
10 |
Correct |
13 ms |
1884 KB |
Output is correct |
11 |
Correct |
7 ms |
1884 KB |
Output is correct |
12 |
Runtime error |
22 ms |
3940 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
13 |
Runtime error |
40 ms |
5752 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
14 |
Correct |
60 ms |
6592 KB |
Output is correct |
15 |
Runtime error |
187 ms |
9336 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
16 |
Runtime error |
247 ms |
9716 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
17 |
Runtime error |
213 ms |
9716 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
18 |
Correct |
79 ms |
9716 KB |
Output is correct |
19 |
Runtime error |
279 ms |
9756 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
20 |
Runtime error |
273 ms |
9844 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |