Submission #531618

# Submission time Handle Problem Language Result Execution time Memory
531618 2022-03-01T06:49:13 Z Koosha_mv Sailing Race (CEOI12_race) C++14
40 / 100
274 ms 4992 KB
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<(x.F)<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first

const int N=505;

int n,k,ans,a[N],deg[N],dp[N][N],pd[N][N];
vector<int> vec,g[N];

void calcdp(int u,int x){
	for(auto v : g[u]){
		int dist=(v-u+n)%n;
		if(dist<=x){
			maxm(dp[u][x],dp[v][x-dist]+1);
			maxm(dp[u][x],pd[v][dist-1]+1);
		}
	}
	maxm(ans,dp[u][x]+(k==1 && deg[u]));
	//cout<<"dp "<<u<<" "<<x<<" -> "<<dp[u][x]<<endl;
}
void calcpd(int u,int x){
	for(auto v : g[u]){
		int dist=(u-v+n)%n;
		if(dist<=x){
			maxm(pd[u][x],pd[v][x-dist]+1);
			maxm(pd[u][x],dp[v][dist-1]+1);
		}
	}
	maxm(ans,pd[u][x]+(k==1 && deg[u]));
	//cout<<"pd "<<u<<" "<<x<<" -> "<<pd[u][x]<<endl;
}

int main(){
	ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin>>n>>k;
	f(i,0,n){
		int x;
		cin>>x;
		while(x>0){
			deg[x-1]=1;
			g[i].pb(x-1);
			cin>>x;
		}
	}
	f(t,1,n){
		f(i,0,n){
			calcdp(i,t);
			calcpd(i,t);
		}
	}
	int res=0;
	if(k==0){
		f(i,0,n) if(dp[i][n-1]==ans || pd[i][n-1]==ans) res=i+1;
	}
	else{
		f(i,0,n){
			if(dp[i][n-1]+(deg[i]>0)==ans || pd[i][n-1]+(deg[i]>0)==ans){
				if(deg[i]==0){
					res=i+1;
				}
				else{
					f(j,0,n){
						for(auto v : g[j]){
							if(v==i){
								res=j+1;
							}
						}
					}
				}
				break;
			}
		}
	}
	if(k==1) assert(0);
	cout<<ans<<endl<<res;
}
/*
7 1
5 0
5 0
7 0
3 0
4 0
4 3 0
2 1 0
*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Runtime error 1 ms 588 KB Execution killed with signal 6
3 Runtime error 1 ms 716 KB Execution killed with signal 6
4 Runtime error 2 ms 844 KB Execution killed with signal 6
5 Correct 1 ms 460 KB Output is correct
6 Runtime error 3 ms 964 KB Execution killed with signal 6
7 Correct 4 ms 716 KB Output is correct
8 Runtime error 2 ms 1100 KB Execution killed with signal 6
9 Correct 5 ms 708 KB Output is correct
10 Correct 12 ms 716 KB Output is correct
11 Correct 5 ms 744 KB Output is correct
12 Runtime error 17 ms 2124 KB Execution killed with signal 6
13 Runtime error 30 ms 2960 KB Execution killed with signal 6
14 Correct 47 ms 1868 KB Output is correct
15 Runtime error 161 ms 4736 KB Execution killed with signal 6
16 Runtime error 268 ms 4976 KB Execution killed with signal 6
17 Runtime error 164 ms 4736 KB Execution killed with signal 6
18 Correct 64 ms 2320 KB Output is correct
19 Runtime error 274 ms 4992 KB Execution killed with signal 6
20 Runtime error 260 ms 4932 KB Execution killed with signal 6