# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1091093 | vjudge1 | Sailing Race (CEOI12_race) | C++17 | 1178 ms | 4460 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
bool g[501][501];
int dp[501][501][2];
int n;
void najdi(int l,int r,int i)
{
if(dp[l][r][i]!=-1)return;
int d=r;
if(i==1)
{
d=l;
}
int res=0;
for(int j=(l+1)%n;j!=r;j=(j+1)%n)
{
if(g[d][j])
{
najdi(l,j,0);
najdi(j,r,1);
res=max(res,1+max(dp[l][j][0],dp[j][r][1]));
}
}
dp[l][r][i]=res;
cout<<res<<endl;
}
int main()
{
int k;
cin>>n>>k;
int ans=0,res=0,x=0;
for(int i=0;i<n;i++)
{
int a;
for(int j=0;j<n;j++)
{
dp[i][j][0]=-1;
dp[i][j][1]=-1;
}
while(cin>>a&&a!=0)
{
g[i][a-1]=1;
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(g[i][j])
{
najdi(i,j,0);
najdi(j,i,1);
res=max(res,1+max(dp[i][j][0],dp[j][i][1]));
if(res>ans)
{
x=i;
ans=res;
}
}
}
}
cout<<ans<<" "<<x+1;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |