Submission #25394

# Submission time Handle Problem Language Result Execution time Memory
25394 2017-06-22T04:02:10 Z 김동현(#1064) Watching (JOI13_watching) C++14
50 / 100
1000 ms 17808 KB
#include <bits/stdc++.h>
using namespace std;

int n, p, q, a[2010], dp[2010][2010];

int can(int x){
	for(int i = 0; i <= p; i++){
		for(int j = !i; j <= q; j++){
			dp[i][j] = 0;
			if(i) dp[i][j] = max(dp[i][j], (int)(upper_bound(a + 1, a + n + 1, (int)(a[dp[i - 1][j] + 1] + x - 1)) - a - 1));
			if(j) dp[i][j] = max(dp[i][j], (int)(upper_bound(a + 1, a + n + 1, (int)(a[dp[i][j - 1] + 1] + 2LL * x - 1)) - a - 1));
			if(dp[i][j] == n) return 1;
		}
	}
	return 0;
}

int main(){
	scanf("%d%d%d", &n, &p, &q);
	if(p + q >= n){ puts("1"); return 0; }
	for(int i = 1; i <= n; i++) scanf("%d", a + i);
	sort(a + 1, a + n + 1);
	int s = 1, e = 1e9 + 1;
	while(s <= e){
		int m = (s + e) / 2;
		if(can(m)) e = m - 1;
		else s = m + 1;
	}
	printf("%d\n", s);
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:19:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d", &n, &p, &q);
                             ^
watching.cpp:21:48: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 1; i <= n; i++) scanf("%d", a + i);
                                                ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 17808 KB Output is correct
2 Correct 0 ms 17808 KB Output is correct
3 Correct 0 ms 17808 KB Output is correct
4 Correct 0 ms 17808 KB Output is correct
5 Correct 0 ms 17808 KB Output is correct
6 Correct 0 ms 17808 KB Output is correct
7 Correct 0 ms 17808 KB Output is correct
8 Correct 0 ms 17808 KB Output is correct
9 Correct 0 ms 17808 KB Output is correct
10 Correct 0 ms 17808 KB Output is correct
11 Correct 0 ms 17808 KB Output is correct
12 Correct 0 ms 17808 KB Output is correct
13 Correct 0 ms 17808 KB Output is correct
14 Correct 0 ms 17808 KB Output is correct
15 Correct 0 ms 17808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 17808 KB Output is correct
2 Correct 0 ms 17808 KB Output is correct
3 Correct 0 ms 17808 KB Output is correct
4 Correct 0 ms 17808 KB Output is correct
5 Correct 0 ms 17808 KB Output is correct
6 Correct 0 ms 17808 KB Output is correct
7 Correct 0 ms 17808 KB Output is correct
8 Correct 169 ms 17808 KB Output is correct
9 Correct 113 ms 17808 KB Output is correct
10 Correct 149 ms 17808 KB Output is correct
11 Correct 113 ms 17808 KB Output is correct
12 Execution timed out 1000 ms 17808 KB Execution timed out
13 Halted 0 ms 0 KB -