#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, 0, n) {
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) FOR(j, 0, n) {
if (dp[i][j][0] > ans) ans = dp[i][j][0], best = i;
if (dp[i][j][1] > ans) ans = dp[i][j][1], best = j;
}
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 |
5 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 |
512 KB |
Output is correct |
6 |
Incorrect |
5 ms |
640 KB |
Unexpected end of file - int32 expected |
7 |
Incorrect |
6 ms |
640 KB |
Output isn't correct |
8 |
Incorrect |
6 ms |
640 KB |
Unexpected end of file - int32 expected |
9 |
Incorrect |
7 ms |
768 KB |
Output isn't correct |
10 |
Incorrect |
11 ms |
768 KB |
Output isn't correct |
11 |
Incorrect |
8 ms |
768 KB |
Output isn't 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 |
36 ms |
1920 KB |
Output is correct |
15 |
Incorrect |
100 ms |
2680 KB |
Unexpected end of file - int32 expected |
16 |
Incorrect |
120 ms |
2560 KB |
Unexpected end of file - int32 expected |
17 |
Incorrect |
98 ms |
2508 KB |
Unexpected end of file - int32 expected |
18 |
Correct |
46 ms |
2432 KB |
Output is correct |
19 |
Incorrect |
139 ms |
2560 KB |
Unexpected end of file - int32 expected |
20 |
Incorrect |
140 ms |
2560 KB |
Unexpected end of file - int32 expected |