#define here cerr<<"===========================================\n"
#define dbg(x) cerr<<#x<<": "<<x<<endl;
#include <bits/stdc++.h>
#define ld double
#define ll long long
#define ull unsigned long long
#define llinf 100000000000000000LL // 10^17
#define iinf 2000000000 // 2*10^9
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define all(a) a.begin(),a.end()
using namespace std;
#define maxn 505
ll n,tip;
ll dp[maxn][maxn][2];
bool d[maxn][maxn];
ll nx[maxn][2];
void solv(ll l,ll r,ll x){
dp[l][r][x] = 0;
for(ll tr = r;tr!=l;tr = nx[tr][x^1]) if(d[l][tr]) dp[l][r][x] = max(dp[l][r][x],1 + dp[tr][nx[l][x]][x^1]);
for(ll tl = l;tl!=r;tl = nx[tl][x]) if(d[l][tl]) dp[l][r][x] = max(dp[l][r][x],1 + dp[tl][r][x]);
}
int main(){
cin >> n >> tip;
for(ll i = 1;i<=n;i++){
ll x = -1;
while(x!=0){
cin >> x;
d[i][x] = 1;
}
}
for(ll i = 1;i<=n;i++){
nx[i][0] = i+1;
nx[i][1] = i-1;
if(nx[i][0]==n+1) nx[i][0] = 1;
if(nx[i][1]==0) nx[i][1] = n;
}
for(ll d = 1;d<=n;d++){
for(ll l = 1;l<=n;l++){
ll r = l+d;
if(r>n) r-=n;
solv(l,r,0);
solv(r,l,1);
}
}
pll ans = {-1,0};
for(ll i = 1;i<=n;i++){
for(ll j = 1;j<=n;j++){
for(ll x = 0;x<2;x++){
ans = max(ans,{dp[i][j][x],i});
}
}
}
cout<<ans.fi<<endl;
cout<<ans.sc<<endl;
return (0-0);
}
/**
7 0
5 0
5 0
7 0
3 0
4 0
4 3 0
2 1 0
**/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Incorrect |
3 ms |
596 KB |
Output isn't correct |
7 |
Correct |
4 ms |
596 KB |
Output is correct |
8 |
Incorrect |
5 ms |
768 KB |
Output isn't correct |
9 |
Correct |
9 ms |
816 KB |
Output is correct |
10 |
Correct |
10 ms |
852 KB |
Output is correct |
11 |
Correct |
14 ms |
888 KB |
Output is correct |
12 |
Incorrect |
79 ms |
1820 KB |
Output isn't correct |
13 |
Incorrect |
181 ms |
2720 KB |
Output isn't correct |
14 |
Correct |
397 ms |
3684 KB |
Output is correct |
15 |
Incorrect |
942 ms |
4496 KB |
Output isn't correct |
16 |
Incorrect |
1045 ms |
4624 KB |
Output isn't correct |
17 |
Incorrect |
1038 ms |
4500 KB |
Output isn't correct |
18 |
Correct |
818 ms |
4500 KB |
Output is correct |
19 |
Incorrect |
1152 ms |
4500 KB |
Output isn't correct |
20 |
Incorrect |
1168 ms |
4492 KB |
Output isn't correct |