# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
887170 | VicBVic | Sailing Race (CEOI12_race) | C++17 | 47 ms | 1628 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;
const int MN = 505;
int d[MN][MN];
int n,k;
bool adj[MN][MN];
int main()
{
cin>>n>>k;
assert(k==0);
for(int i=1;i<=n;i++)
{
int nr=-1;
while(true)
{
cin>>nr;
if(!nr) break;
adj[i][nr]=1;
}
}
for(int l=1;l<n;l++)
{
for(int i=1;i+l<=n;i++)
{
int j=i+l;
for(int y=i+1;y<=j;y++)
{
if(adj[i][y]) d[i][j]=max(d[i][j],1 + max( d[y][i+1], d[y][j]));
}
for(int y=j-1;y>=i;y--)
{
if(adj[j][y]) d[j][i]=max(d[j][i],1 + max( d[y][j-1], d[y][i]));
}
}
}
int mx=0, mxc=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(d[i][j]>mx) mx=d[i][j], mxc=i;
}
}
cout<<mx<<'\n'<<mxc<<'\n';
return 0;
}
/*
7 0
5 0
5 0
7 0
3 0
4 0
4 3 0
2 1 0
5 2
*/
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |