Submission #59292

# Submission time Handle Problem Language Result Execution time Memory
59292 2018-07-21T12:12:28 Z IvanC Sailing Race (CEOI12_race) C++17
40 / 100
208 ms 9428 KB
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 1010;

vector<int> grafo[MAXN];
int dp[MAXN][MAXN],N,K;


int solve(int i,int j){
	if(dp[i][j] != -1) return dp[i][j];
	if(i == j) return dp[i][j] = 0;
	int best = 0;
	
	if(i < j){
		for(int k : grafo[i]){
			if(k >= min(i,j) && k <= max(i,j)){
				int candidate = max(solve(k,j),solve(k,i+1)) + 1;
				best = max(best,candidate);
			}
		}
	}
	else{
		for(int k : grafo[i]){
			if(k >= min(i,j) && k <= max(i,j)){
				int candidate = max(solve(k,i-1),solve(k,j)) + 1;
				best = max(best,candidate);
			}
		}
	}
	
	return dp[i][j] = best;	
	
}

void adiciona(int i,int j){
	grafo[i].push_back(j);
	grafo[i].push_back(j+N);
	grafo[i+N].push_back(j);
	grafo[i+N].push_back(j+N);
}

int main(){
	
	memset(dp,-1,sizeof(dp));
	cin >> N >> K;
	assert(K != 1);
	
	for(int i = 1;i<=N;i++){
		int x;
		while(cin >> x && x){
			adiciona(i,x);
		}
	}
	
	int best = -1,ans = 0;
	for(int i = 1,j = N;i<=N;i++,j++){
		int candidate = solve(i,j);
		if(candidate > best){
			best = candidate;
			ans = i;
		}
	}
	
	cout << best << endl << ans << endl;
	
	return 0;
	
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4344 KB Output is correct
2 Runtime error 11 ms 8684 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 12 ms 8684 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 11 ms 8748 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Correct 7 ms 8952 KB Output is correct
6 Runtime error 11 ms 8952 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Correct 13 ms 8952 KB Output is correct
8 Runtime error 11 ms 8952 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Correct 18 ms 9000 KB Output is correct
10 Correct 26 ms 9156 KB Output is correct
11 Correct 16 ms 9156 KB Output is correct
12 Runtime error 15 ms 9156 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Runtime error 10 ms 9156 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Correct 108 ms 9192 KB Output is correct
15 Runtime error 10 ms 9192 KB Execution killed with signal 11 (could be triggered by violating memory limits)
16 Runtime error 12 ms 9192 KB Execution killed with signal 11 (could be triggered by violating memory limits)
17 Runtime error 15 ms 9192 KB Execution killed with signal 11 (could be triggered by violating memory limits)
18 Correct 208 ms 9428 KB Output is correct
19 Runtime error 12 ms 9428 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Runtime error 13 ms 9428 KB Execution killed with signal 11 (could be triggered by violating memory limits)