답안 #25397

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
25397 2017-06-22T04:06:06 Z kdh9949 구경하기 (JOI13_watching) C++14
100 / 100
76 ms 17824 KB
#include <bits/stdc++.h>
using namespace std;

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

int can(int x){
	for(int i = 1; i <= n; i++){
		nx[0][i] = (int)(upper_bound(a + 1, a + n + 1, (int)(a[i] + x - 1)) - a - 1);
		nx[1][i] = (int)(upper_bound(a + 1, a + n + 1, (int)(a[i] + 2LL * x - 1)) - a - 1);
	}
	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], nx[0][dp[i - 1][j] + 1]);
			if(j) dp[i][j] = max(dp[i][j], nx[1][dp[i][j - 1] + 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:23: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:25: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);
                                                ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 17824 KB Output is correct
2 Correct 0 ms 17824 KB Output is correct
3 Correct 0 ms 17824 KB Output is correct
4 Correct 0 ms 17824 KB Output is correct
5 Correct 0 ms 17824 KB Output is correct
6 Correct 0 ms 17824 KB Output is correct
7 Correct 0 ms 17824 KB Output is correct
8 Correct 0 ms 17824 KB Output is correct
9 Correct 0 ms 17824 KB Output is correct
10 Correct 0 ms 17824 KB Output is correct
11 Correct 0 ms 17824 KB Output is correct
12 Correct 0 ms 17824 KB Output is correct
13 Correct 0 ms 17824 KB Output is correct
14 Correct 0 ms 17824 KB Output is correct
15 Correct 0 ms 17824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 17824 KB Output is correct
2 Correct 0 ms 17824 KB Output is correct
3 Correct 0 ms 17824 KB Output is correct
4 Correct 0 ms 17824 KB Output is correct
5 Correct 0 ms 17824 KB Output is correct
6 Correct 0 ms 17824 KB Output is correct
7 Correct 3 ms 17824 KB Output is correct
8 Correct 13 ms 17824 KB Output is correct
9 Correct 16 ms 17824 KB Output is correct
10 Correct 23 ms 17824 KB Output is correct
11 Correct 13 ms 17824 KB Output is correct
12 Correct 76 ms 17824 KB Output is correct
13 Correct 6 ms 17824 KB Output is correct
14 Correct 6 ms 17824 KB Output is correct
15 Correct 6 ms 17824 KB Output is correct