#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n, k, i, j, l, r, d, t;
cin >> n >> k;
vector<vector<int> > le(n), ri(n);
vector<vector<bool> > w(n);
for (i = 0; i < n; i++)
{
le[i].resize(n);
ri[i].resize(n);
w[i].resize(n);
for (j = 0; j < n; j++)
w[i][j] = 0;
while (1)
{
cin >> d;
if (!d)
break;
w[i][d - 1] = 1;
}
}
for (i = 0; i < n; i++)
{
for (l = 0; l < n; l++)
{
r = (l + i) % n;
le[l][r] = ri[l][r] = 0;
for (j = 1; j < i; j++)
{
d = (l + j) % n;
t = max(ri[l][d], le[d][r]) + 1;
if (w[l][d])
le[l][r] = max(le[l][r], t);
if (w[r][d])
ri[l][r] = max(ri[l][r], t);
}
}
}
t = r = 0;
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
l = 0;
if (w[i][j])
l = max(ri[i][j], le[j][i]) + 1;
if (l > t)
{
t = l;
r = i;
}
}
}
cout << t << "\n" << r + 1;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
9 |
Correct |
5 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
348 KB |
Output is correct |
11 |
Correct |
7 ms |
344 KB |
Output is correct |
12 |
Incorrect |
25 ms |
800 KB |
Output isn't correct |
13 |
Incorrect |
61 ms |
1180 KB |
Output isn't correct |
14 |
Correct |
132 ms |
1624 KB |
Output is correct |
15 |
Incorrect |
351 ms |
2396 KB |
Output isn't correct |
16 |
Incorrect |
379 ms |
2396 KB |
Output isn't correct |
17 |
Incorrect |
321 ms |
2484 KB |
Output isn't correct |
18 |
Correct |
273 ms |
2392 KB |
Output is correct |
19 |
Incorrect |
430 ms |
2396 KB |
Output isn't correct |
20 |
Incorrect |
434 ms |
2392 KB |
Output isn't correct |