답안 #765837

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
765837 2023-06-25T06:16:42 Z yusuf12360 구경하기 (JOI13_watching) C++14
100 / 100
539 ms 15340 KB
#include<bits/stdc++.h>
using namespace std;
vector<int> a;
int n, p, q;
bool can(int w) {
	vector<vector<int>> dp(n, vector<int>(p+1));
	vector<int> small_dist(n), big_dist(n);
	int SMALL=0, BIG=0;
	for(int i=0; i<n; i++) {
		if(a[0]>=a[i]-w+1) small_dist[i]=-1;
		else {
			while(a[SMALL]<a[i]-w+1) SMALL++;
			small_dist[i]=--SMALL;
		}
		if(a[0]>=a[i]-2*w+1) big_dist[i]=-1;
		else {
			while(a[BIG]<a[i]-2*w+1) BIG++;
			big_dist[i]=--BIG;
		}
	}
	for(auto &p : dp) for(int &pp : p) pp=1e4;
	dp[0][0]=1;
	for(int i=1; i<=p; i++) dp[0][1]=0;
	for(int i=1; i<n; i++) {
		for(int j=0; j<=p; j++) {
			SMALL=small_dist[i], BIG=big_dist[i];
			if(j) {
				if(SMALL==-1) dp[i][j]=0;
				else dp[i][j]=min(dp[i][j], dp[SMALL][j-1]);
			}
			if(BIG==-1) dp[i][j]=min(dp[i][j], 1);
			else dp[i][j]=min(dp[i][j], dp[BIG][j]+1);
		}
	}
	for(int i=0; i<=p; i++) {if(dp[n-1][i]<=q) return 1;}
	return 0;
}
int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> p >> q;
	a.resize(n);
	for(int &p : a) cin >> p;
	if(p+q>=n) {cout << "1\n"; return 0;}
	sort(a.begin(), a.end());
	int l=1, r=1e9, w=1e9;
	while(l<=r) {
		int mid=(l+r)/2;
		if(can(mid)) w=mid, r=mid-1;
		else l=mid+1;
	}
	cout << w << '\n';
	return 0;
}
# 결과 실행 시간 메모리 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 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 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 460 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 5 ms 468 KB Output is correct
8 Correct 41 ms 1484 KB Output is correct
9 Correct 161 ms 6360 KB Output is correct
10 Correct 539 ms 15340 KB Output is correct
11 Correct 30 ms 1124 KB Output is correct
12 Correct 215 ms 8184 KB Output is correct
13 Correct 5 ms 468 KB Output is correct
14 Correct 6 ms 596 KB Output is correct
15 Correct 6 ms 568 KB Output is correct