# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
679072 | vjudge1 | Sailing Race (CEOI12_race) | C++17 | 225 ms | 6668 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1005;
int n, k, dp[MAXN][MAXN][2][2], ans, ans_node;
vector<int> adj[MAXN];
bool bio[MAXN];
int cur_i, cur_j, cur_b;
int main(){
cin >> n >> k;
for(int i = 0; i < n; ++i){
int x; cin >> x;
while(x){
--x;
adj[i].push_back(x);
cin >> x;
}
}
for(int off = 1; off < n; ++off){
for(int i = 0; i < n; ++i){
int j = (i + off) % n;
for(int x : adj[i]){
if((i < j && i < x && x <= j) || (i > j && (i < x || x <= j))){
dp[i][j][0][0] = max(dp[i][j][0][0], max(dp[(i + 1) % n][x][1][1], dp[x][j][0][0]) + 1);
dp[i][j][0][1] = max(dp[i][j][0][1], max(dp[(i + 1) % n][x][1][1], dp[x][j][0][1]) + 1);
}
}
for(int x : adj[j]){
if((i < j && i <= x && x < j) || (i > j && (i <= x || x < j))){
dp[i][j][1][0] = max(dp[i][j][1][0], max(dp[i][x][1][0], dp[x][(j - 1 + n) % n][0][1]) + 1);
dp[i][j][1][1] = max(dp[i][j][1][1], max(dp[i][x][1][1], dp[x][(j - 1 + n) % n][0][1]) + 1);
}
}
ans = max(ans, dp[i][j][0][0]);
ans = max(ans, dp[i][j][1][0]);
if(dp[i][j][0][0] == ans){
ans_node = i;
}
if(dp[i][j][1][0] == ans){
ans_node = j;
}
}
}
cout << ans << "\n" << ans_node + 1;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |