# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1091085 | vjudge1 | Sailing Race (CEOI12_race) | C++17 | 394 ms | 3408 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,m;
vector<vector<int> > adj(501);
/// levo, desno, dali sme kaj levio element ili desnio, clockwise
bool visited[501][501][2];
int dp[501][501][2];
bool mat[501][501];
int f(int l,int r,int poz)
{
//cout<< "l="<<l<<" r="<<r<<" poz="<<poz<<endl;
//system("pause");
//cout<<endl;
bool t = (l==poz);
if (visited[l][r][t]) return dp[l][r][t];
int odg = 0;
for (int sosed = l+1;sosed!=r;sosed++)
{
if (sosed>n) sosed = 1;
if (r == sosed) break;
if (mat[poz][sosed])
{
odg = max(f(l,sosed,sosed)+1,odg);
odg = max(f(sosed,r,sosed)+1,odg);
}
}
visited[l][r][t] = true;
dp[l][r][t] = odg;
return odg;
}
int main()
{
cin>>n>>m;
for (int i=1;i<=n;i++)
{
int a;
while(true)
{
cin>>a;
if (a==0) break;
//adj[i].push_back(a);
mat[i][a] = true;
}
}
int odg = 0, p = 0;
for (int i=1;i<=n;i++)
{
int x = f(i,i,i);
if (x>odg)
{
odg = x;
p = i;
}
//cout<< "za i="<<i<< " odg = "<<x<<endl;
}
cout<<odg<<endl<<p<<endl;
return 0;
}
/*
7 1
5 0
5 0
7 0
3 0
4 0
4 3 0
2 1 0
*/
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |