# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
998593 | doducanh | Sailing Race (CEOI12_race) | C++14 | 850 ms | 5572 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
int edge[505][505];
int dp[505][505][2];
int dp1[505][505][2];
int nx[505][2];
int n,type;
void solve(int l,int r,int x)
{
if(edge[l][r]){
dp[l][r][x]=1;
dp1[l][r][x]=1+dp1[r][nx[l][x]][x^1];
}
else{
dp[l][r][x]=-n;
dp1[l][r][x]=-n;
}
for(int m=nx[l][x];m!=r;m=nx[m][x]){
dp[l][r][x]=max(dp[l][r][x],dp[l][m][x]+dp[m][r][x]);
dp1[l][r][x]=max(dp1[l][r][x],dp[l][m][x]+dp1[m][r][x]);
}
dp1[l][r][x]=max(dp1[l][r][x],dp1[l][nx[r][x^1]][x]);
}
main()
{
cin>>n>>type;
for(int i=0;i<n;i++){
int x;
cin>>x;
while(x!=0){
edge[i][x-1]=1;
cin>>x;
}
nx[i][0]=(i+1)%n;
nx[i][1]=(i+n-1)%n;
}
for(int d=1;d<n;d++){
for(int l=0,r=(l+d)%n;l<n;l++,r=nx[r][0]){
solve(l,r,0);
solve(r,l,1);
}
}
pair<int,int>ans={-1,0};
for(int l=0;l<n;l++){
for(int r=0;r<n;r++){
for(int x=0;x<2;x++){
ans=max(ans,{dp1[l][r][x],l+1});
}
}
}
if(type){
for(int l=0;l<n;l++){
for(int r=0;r<n;r++){
for(int x=0;x<2;x++){
if(dp[l][r][x]<=0)continue;
int st=nx[r][x];
while(st!=l&&edge[st][l]==0)st=nx[st][x];
if(st==l)continue;
for(int ed=nx[st][x];ed!=l;ed=nx[ed][x]){
if(edge[r][ed]){
ans=max(ans,make_pair(max(dp1[ed][nx[l][x^1]][x],dp1[ed][nx[st][x]][x^1])+1+1+dp[l][r][x],st+1));
}
}
}
}
}
}
cout<<ans.fi<<"\n"<<ans.se;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |