#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[(i + k) % n]) {
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][j][1]) + 1);
}
}
}
}
if (t) {
} else {
int ans = 0, best = -1;
FOR(k, 0, n + 1) FOR(i, 0, n) {
if (dp[i][(i + k) % n][0] > ans) ans = dp[i][(i + k) % n][0], best = i;
if (dp[i][(i + k) % n][1] > ans) ans = dp[i][(i + k) % n][1], best = (i + k) % n;
}
cout << ans << '\n' << best + 1;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
512 KB |
Output isn't correct |
2 |
Incorrect |
5 ms |
512 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 |
Incorrect |
5 ms |
512 KB |
Output isn't 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 |
692 KB |
Output isn't correct |
10 |
Incorrect |
12 ms |
768 KB |
Output isn't correct |
11 |
Incorrect |
9 ms |
768 KB |
Output isn't correct |
12 |
Incorrect |
15 ms |
1152 KB |
Unexpected end of file - int32 expected |
13 |
Incorrect |
24 ms |
1536 KB |
Unexpected end of file - int32 expected |
14 |
Incorrect |
38 ms |
2048 KB |
Output isn't correct |
15 |
Incorrect |
108 ms |
2560 KB |
Unexpected end of file - int32 expected |
16 |
Incorrect |
138 ms |
2688 KB |
Unexpected end of file - int32 expected |
17 |
Incorrect |
110 ms |
2612 KB |
Unexpected end of file - int32 expected |
18 |
Incorrect |
49 ms |
2432 KB |
Output isn't correct |
19 |
Incorrect |
161 ms |
2816 KB |
Unexpected end of file - int32 expected |
20 |
Incorrect |
160 ms |
2784 KB |
Unexpected end of file - int32 expected |