답안 #707942

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
707942 2023-03-10T14:36:52 Z Dan4Life 구경하기 (JOI13_watching) C++17
100 / 100
255 ms 16200 KB
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
const int mxN = (int)2e3+10;
const int LINF = (int)1e9;
int n, p, q;
int a[mxN], P[mxN], Q[mxN], v[mxN], dp[mxN][mxN];

bool work(int w){
	for(int i=2,j=1,k=1; i <= n; i++){
		v[i]=v[i-1]+a[i]-a[i-1];
		while(v[i]-v[j]+1>w) j++;
		while(v[i]-v[k]+1>2*w) k++;
		P[i]=j-1,Q[i]=k-1;
	}
	for(int i = 1; i <= n; i++){
		for(int j = 0; j <= q; j++){
			dp[i][j] = min(LINF, dp[P[i]][j]+1);
			if(j) dp[i][j] = min(dp[i][j], dp[Q[i]][j-1]);
		}
	}
	return dp[n][q]<=p;
}

int32_t main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n >> p >> q;
	for(int i = 1; i <= n; i++) cin >> a[i];
	sort(a+1,a+n+1); v[1]=a[1];
	if(p+q>=n){cout<<1;return 0;}
	int l = 1, r = (int)1e9;
	while(l<r){
		int mid = (l+r)/2;
		if(work(mid)) r=mid;
		else l=mid+1;
	}
	cout << l;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 1 ms 724 KB Output is correct
11 Correct 1 ms 724 KB Output is correct
12 Correct 1 ms 724 KB Output is correct
13 Correct 1 ms 724 KB Output is correct
14 Correct 1 ms 724 KB Output is correct
15 Correct 1 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8276 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 7 ms 8404 KB Output is correct
8 Correct 113 ms 14236 KB Output is correct
9 Correct 22 ms 9300 KB Output is correct
10 Correct 18 ms 9072 KB Output is correct
11 Correct 255 ms 16200 KB Output is correct
12 Correct 144 ms 15956 KB Output is correct
13 Correct 7 ms 8404 KB Output is correct
14 Correct 6 ms 8404 KB Output is correct
15 Correct 6 ms 8404 KB Output is correct