답안 #797859

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
797859 2023-07-30T03:38:26 Z OrazB 구경하기 (JOI13_watching) C++14
100 / 100
257 ms 8148 KB
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()

const int N = 2e3+5;
int a[N];

int main ()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, p, q;
	cin >> n >> p >> q;
	for (int i = 1; i <= n; i++) cin >> a[i];
	sort(a+1,a+n+1);
	if (p+q >= n) return cout << 1, 0;
	int l = 1, r = 1e9, ans = -1;
	while(l <= r){
		int md = (l+r)>>1;
		vector<vector<int>> dp(n+1, vector<int>(min(p+1,q+1), 1e9));
		for (int i = 0; i <= min(p,q); i++) dp[0][i] = 0;
		int pos1 = 1, pos2 = 1;
		for (int i = 1; i <= n; i++){
			for (int j = 0; j <= min(p,q); j++){
				while(a[pos1] <= a[i]-md) pos1++;
				while(a[pos2] <= a[i]-2*md) pos2++;
				if (p <= q){
					if (j) dp[i][j] = min(dp[i][j], dp[pos1-1][j-1]);
					dp[i][j] = min(dp[i][j], dp[pos2-1][j]+1);
				}else{
					if (j) dp[i][j] = min(dp[i][j], dp[pos2-1][j-1]);
					dp[i][j] = min(dp[i][j], dp[pos1-1][j]+1);
				}
			}
		}
		if (*min_element(all(dp[n])) <= max(p,q)){
			ans = md;
			r = md - 1;
		}else l = md + 1;
	}
	cout << ans;
}	
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 5 ms 540 KB Output is correct
8 Correct 34 ms 1476 KB Output is correct
9 Correct 37 ms 1420 KB Output is correct
10 Correct 26 ms 1092 KB Output is correct
11 Correct 23 ms 1092 KB Output is correct
12 Correct 257 ms 8148 KB Output is correct
13 Correct 5 ms 468 KB Output is correct
14 Correct 6 ms 460 KB Output is correct
15 Correct 6 ms 468 KB Output is correct