답안 #66341

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
66341 2018-08-10T09:09:17 Z ikura355 Sailing Race (CEOI12_race) C++14
40 / 100
1247 ms 3972 KB
#include<bits/stdc++.h>
using namespace std;
const int maxn = 500 + 5;
int n,k;
int way[maxn][maxn];
int dp[maxn][maxn][2];
int f(int u, int v, int t) {
	if(dp[u][v][t]==-1) {
        dp[u][v][t] = 0;
        int wow = (t==0 ? 1:-1);
		for(int x=(u+wow+n)%n;x!=v;x=(x+wow+n)%n) {
			if(!way[u][x]) continue;
			dp[u][v][t] = max(dp[u][v][t], max(f(x,u,!t), f(x,v,t)) + 1);
		}
	}
	return dp[u][v][t];
}
int main() {
	scanf("%d%d",&n,&k);
	if(k) assert(0);
	for(int u=0;u<n;u++) {
		int v;
		while(scanf("%d",&v) && v) way[u][v-1] = 1;
	}
	memset(dp,-1,sizeof(dp));
	pair<int,int> res = {-1,-1};
	for(int u=0;u<n;u++) res = max(res, {f(u,u,0), u});
	printf("%d\n%d",res.first,res.second+1);
}

Compilation message

race.cpp: In function 'int main()':
race.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&k);
  ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2296 KB Output is correct
2 Runtime error 4 ms 2296 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 3 ms 2296 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 4 ms 2296 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Correct 8 ms 2728 KB Output is correct
6 Runtime error 3 ms 2728 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Correct 10 ms 2732 KB Output is correct
8 Runtime error 4 ms 2732 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Correct 18 ms 2992 KB Output is correct
10 Correct 24 ms 3056 KB Output is correct
11 Correct 25 ms 3056 KB Output is correct
12 Runtime error 3 ms 3056 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Runtime error 3 ms 3056 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Correct 719 ms 3608 KB Output is correct
15 Runtime error 3 ms 3608 KB Execution killed with signal 11 (could be triggered by violating memory limits)
16 Runtime error 3 ms 3608 KB Execution killed with signal 11 (could be triggered by violating memory limits)
17 Runtime error 3 ms 3608 KB Execution killed with signal 11 (could be triggered by violating memory limits)
18 Correct 1247 ms 3972 KB Output is correct
19 Runtime error 2 ms 3972 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Runtime error 3 ms 3972 KB Execution killed with signal 11 (could be triggered by violating memory limits)