# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
132235 | amoo_safar | Sailing Race (CEOI12_race) | C++14 | 1579 ms | 2680 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
const int Maxn = 5e2 + 10;
bool G[Maxn][Maxn];
int n, dp[Maxn][Maxn][2];
int nxt(int y){
return (y + 1) % n;
}
int prev(int y){
return (y - 1 + n) % n;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int k;
cin >> n >> k;
if(k == 1){
cout << G[5000][5000];
return 0;
}
int adj;
for(int i = 0; i < n; i++){
while(true){
cin >> adj;
adj --;
if(adj == -1) break;
G[i][adj] = true;
}
}
for(int l = 1; l <= n; l++){
for(int i = 0; i < n; i++){
int j = (i + l) % n;
dp[i][j][0] = 1;
for(int k = nxt(i); k != j; k = nxt(k)){
if(G[i][k]) dp[i][j][0] = max( dp[i][j][0], max(dp[k][j][0], dp[k][i][1]) + 1);
}
dp[i][j][1] = 1;
for(int k = prev(i); k != j; k = prev(k)){
if(G[i][k]) dp[i][j][1] = max( dp[i][j][1], max(dp[k][j][1], dp[k][i][0]) + 1);
}
}
}
int ans = 0, st = 0;
for(int i = 0; i < n; i++){
ans = max(ans, dp[i][i][0]);
if(ans == dp[i][i][0]) st = i;
}
cout << ans << '\n' << st + 1 << '\n';
return 0;
}
/*
7 1
5 0
5 0
7 0
3 0
4 0
4 3 0
2 1 0
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |