#include <bits/stdc++.h>
#define FOR(i, x, y) for (int i = x; i < y; i++)
typedef long long ll;
using namespace std;
vector<int> graph[501];
int dp[501][501][2];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, t;
cin >> n >> t;
FOR(i, 0, n) {
int v;
cin >> v;
while (v) {
graph[i].push_back(v - 1);
cin >> v;
}
}
FOR(k, 1, n + 1) {
FOR(i, 0, n) {
int j = (i + k) % n;
for (int v : graph[i]) {
if ((v > i && v < i + k) || (v > i - n && v < i + k - n)) {
dp[i][j][0] = max(dp[i][j][0], max(dp[v][j][0], dp[i][v][1]) + 1);
}
}
for (int v : graph[j]) {
if ((v > i && v < i + k) || (v > i - n && v < i + k - n)) {
dp[i][j][1] = max(dp[i][j][1], max(dp[v][j][0], dp[i][v][1]) + 1);
}
}
}
}
if (t) {
} else {
int ans = 0, best = -1;
FOR(i, 0, n) if (max(dp[i][i][0], dp[i][i][1]) > ans)
ans = max(dp[i][i][0], dp[i][i][1]), best = i;
cout << ans << '\n' << best + 1 << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Incorrect |
5 ms |
384 KB |
Unexpected end of file - int32 expected |
3 |
Incorrect |
4 ms |
512 KB |
Unexpected end of file - int32 expected |
4 |
Incorrect |
5 ms |
512 KB |
Unexpected end of file - int32 expected |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Incorrect |
5 ms |
640 KB |
Unexpected end of file - int32 expected |
7 |
Correct |
6 ms |
640 KB |
Output is correct |
8 |
Incorrect |
5 ms |
640 KB |
Unexpected end of file - int32 expected |
9 |
Correct |
7 ms |
768 KB |
Output is correct |
10 |
Correct |
11 ms |
768 KB |
Output is correct |
11 |
Correct |
8 ms |
768 KB |
Output is correct |
12 |
Incorrect |
14 ms |
1152 KB |
Unexpected end of file - int32 expected |
13 |
Incorrect |
22 ms |
1536 KB |
Unexpected end of file - int32 expected |
14 |
Correct |
35 ms |
1920 KB |
Output is correct |
15 |
Incorrect |
97 ms |
2432 KB |
Unexpected end of file - int32 expected |
16 |
Incorrect |
120 ms |
2680 KB |
Unexpected end of file - int32 expected |
17 |
Incorrect |
99 ms |
2512 KB |
Unexpected end of file - int32 expected |
18 |
Correct |
46 ms |
2424 KB |
Output is correct |
19 |
Incorrect |
141 ms |
2560 KB |
Unexpected end of file - int32 expected |
20 |
Incorrect |
148 ms |
2680 KB |
Unexpected end of file - int32 expected |