#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<<endl<<x+1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
356 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Incorrect |
3 ms |
604 KB |
Output isn't correct |
5 |
Incorrect |
6 ms |
608 KB |
Output isn't correct |
6 |
Incorrect |
8 ms |
608 KB |
Output isn't correct |
7 |
Incorrect |
12 ms |
792 KB |
Output isn't correct |
8 |
Incorrect |
13 ms |
604 KB |
Output isn't correct |
9 |
Incorrect |
25 ms |
1116 KB |
Output isn't correct |
10 |
Incorrect |
27 ms |
956 KB |
Output isn't correct |
11 |
Incorrect |
26 ms |
860 KB |
Output isn't correct |
12 |
Incorrect |
117 ms |
1372 KB |
Output isn't correct |
13 |
Incorrect |
274 ms |
2128 KB |
Output isn't correct |
14 |
Incorrect |
512 ms |
2772 KB |
Output isn't correct |
15 |
Incorrect |
1089 ms |
4080 KB |
Output isn't correct |
16 |
Incorrect |
1147 ms |
4436 KB |
Output isn't correct |
17 |
Incorrect |
1086 ms |
4148 KB |
Output isn't correct |
18 |
Incorrect |
821 ms |
3668 KB |
Output isn't correct |
19 |
Incorrect |
1176 ms |
4376 KB |
Output isn't correct |
20 |
Incorrect |
1162 ms |
4324 KB |
Output isn't correct |