# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1091410 | AtinaR | Sailing Race (CEOI12_race) | C++14 | 400 ms | 4948 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>
using namespace std;
int n,k;
const int MAX=501;
bool mat[MAX][MAX];
int vis[MAX][MAX][2];
int dp[MAX][MAX][2];
int f(int a, int b, int dir)
{
bool t=(dir==a);
if(vis[a][b][t])return dp[a][b][t];
int res=0;
for(int i=a+1; i!=b; i++)
{
if(i==n)i=0;
if(i==b)break;
if(mat[dir][i])
{
res=max(res,f(a,i,i)+1);
res=max(res,f(i,b,i)+1);
}
}
vis[a][b][t]=true;
dp[a][b][t]=res;
return res;
}
int main()
{
cin>>n>>k;
for(int i=0; i<n; i++)
{
int x;
while(cin>>x)
{
if(x==0)break;
x--;
mat[i][x]=true;
}
}
int poz,res=0;
for(int i=0; i<n; i++)
{
int tmp=f(i,i,i);
if(tmp>res)
{
res=tmp;
poz=i;
}
}
cout<<res<<endl<<poz+1<<endl;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |