답안 #765261

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
765261 2023-06-24T10:02:42 Z yusuf12360 구경하기 (JOI13_watching) C++14
0 / 100
1000 ms 39916 KB
#include<bits/stdc++.h>
using namespace std;
vector<int> a;
int n, p, q;
int binser(int x) {
	int l=0, r=n-1, ans=-1;
	while(l<=r) {
		int mid=(l+r)/2;
		if(a[mid]<x) ans=mid, l=mid+1;
		else r=mid-1;
	}
	return ans;
}
bool can(int w) {
	vector<vector<int>> dp(n, vector<int>(p+1));
	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++) {
			int SMALL=binser(a[i]-w+1), BIG=binser(a[i]-2*w+1);
			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);
		}
	}
	return dp[n-1][p]<=q;
}
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;
	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 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Execution timed out 1080 ms 39916 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 456 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Execution timed out 1071 ms 12192 KB Time limit exceeded
4 Halted 0 ms 0 KB -