#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 g[mxn][mxn];
int dp[mxn][mxn][2];
vector<int> gr[mxn];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
for(int i = 0, x; i < n; i++){
for(int j = 0; j < 2; j++) g[j * n + i][j * n + i] = 1;
for(cin >> x; x; cin >> x)
for(int j = 0; j < 2; j++)
for(int l = 0; l < 2; l++){
int u = j * n + i, v = l * n + x - 1;
if(abs(u - v) < n){
g[u][v] = 1;
gr[u].push_back(v);
}
}
}
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 p = 0; p < 2; p++) if(g[i[j]][i[p]])
for(int l : gr[i[p]]) if(l >= i[0] && l <= i[1] && l != i[j]){
int ii[2];
ii[j] = l, ii[!j] = i[!j];
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Incorrect |
1 ms |
620 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
876 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
1004 KB |
Output isn't correct |
5 |
Incorrect |
2 ms |
1260 KB |
Output isn't correct |
6 |
Incorrect |
2 ms |
1388 KB |
Output isn't correct |
7 |
Incorrect |
6 ms |
1644 KB |
Output isn't correct |
8 |
Incorrect |
4 ms |
1772 KB |
Output isn't correct |
9 |
Incorrect |
7 ms |
1900 KB |
Output isn't correct |
10 |
Correct |
23 ms |
2284 KB |
Output is correct |
11 |
Incorrect |
10 ms |
2156 KB |
Output isn't correct |
12 |
Incorrect |
22 ms |
4220 KB |
Output isn't correct |
13 |
Incorrect |
38 ms |
6252 KB |
Output isn't correct |
14 |
Incorrect |
60 ms |
8812 KB |
Output isn't correct |
15 |
Incorrect |
203 ms |
11576 KB |
Output isn't correct |
16 |
Incorrect |
259 ms |
11756 KB |
Output isn't correct |
17 |
Incorrect |
197 ms |
11628 KB |
Output isn't correct |
18 |
Incorrect |
78 ms |
11244 KB |
Output isn't correct |
19 |
Incorrect |
330 ms |
11956 KB |
Output isn't correct |
20 |
Incorrect |
327 ms |
12012 KB |
Output isn't correct |