#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<int, int>
#define f first
#define s second
const int mxn = 1000;
int n, k;
int dp[mxn][mxn][2];
vector<int> g[mxn];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
for(int i = 0, x; i < n; i++)
for(cin >> x; x; cin >> x)
for(int j = 0; j < 2; j++)
for(int l = 0; l < 2; l++){
g[j * n + i].push_back(l * n + x - 1);
}
int ret = 0, x = 0;
for(int i[2] = {0}; i[0] < 2 * n; i[0]++)
for(i[1] = i[0]; i[1] < 2 * n && i[1] - i[0] < n; i[1]++)
for(int j = 0; j < 2; j++){
int &dpc = dp[i[0]][i[1]][j];
for(int l : g[i[j]]) if(l >= i[0] && l <= i[1]){
int ii[2];
ii[!j] = i[!j], ii[j] = l;
for(int p = 0; p < 2; p++){
dpc = max(dpc, dp[ii[0]][ii[1]][p] + 1);
}
}
if(dpc > ret) ret = dpc, x = i[j];
}
cout << ret << " " << (x % n + 1) << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
492 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
620 KB |
Output isn't correct |
4 |
Incorrect |
2 ms |
748 KB |
Output isn't correct |
5 |
Incorrect |
2 ms |
748 KB |
Output isn't correct |
6 |
Incorrect |
3 ms |
876 KB |
Output isn't correct |
7 |
Incorrect |
4 ms |
1004 KB |
Output isn't correct |
8 |
Incorrect |
2 ms |
1132 KB |
Output isn't correct |
9 |
Incorrect |
5 ms |
1260 KB |
Output isn't correct |
10 |
Correct |
12 ms |
1516 KB |
Output is correct |
11 |
Incorrect |
7 ms |
1388 KB |
Output isn't correct |
12 |
Incorrect |
18 ms |
2540 KB |
Output isn't correct |
13 |
Incorrect |
32 ms |
3948 KB |
Output isn't correct |
14 |
Incorrect |
54 ms |
5612 KB |
Output isn't correct |
15 |
Incorrect |
162 ms |
7788 KB |
Output isn't correct |
16 |
Incorrect |
229 ms |
8300 KB |
Output isn't correct |
17 |
Incorrect |
161 ms |
7916 KB |
Output isn't correct |
18 |
Incorrect |
68 ms |
7424 KB |
Output isn't correct |
19 |
Incorrect |
252 ms |
8428 KB |
Output isn't correct |
20 |
Incorrect |
282 ms |
8376 KB |
Output isn't correct |