답안 #365303

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
365303 2021-02-11T12:10:17 Z Bill_00 구경하기 (JOI13_watching) C++14
50 / 100
156 ms 16108 KB
#include <bits/stdc++.h>
using namespace std;
int a[2001];
int dp[2001][2001];
int pre1[2001],pre2[2001];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.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){
		cout << 1;
		return 0;
	}
	int l=1,r=1000000000;
	while(l!=r){
		int mid=l+r>>1;
		int k=0,y=0;
		for(int i=1;i<=p;i++){
			dp[0][i]=0;
		}
		for(int i=1;i<=n;i++){
			dp[i][0]=1e9;
			while((a[i]-mid)>=a[k+1]) k++;
			while((a[i]-2*mid)>=a[y+1]) y++;
			pre1[i]=k;
			pre2[i]=y;
		}
		for(int i=1;i<=n;i++){
			for(int j=1;j<=p;j++){
				int id=pre1[i];
				int id1=pre2[i];
				dp[i][j]=min(dp[id][j-1],dp[id1][j]+1);
			}
		}
		if(dp[n][p]>q){
			l=mid+1;
		}
		else r=mid;
	}
	//cout << l << endl;
	int mid=l,k=0,y=0;
	for(int i=1;i<=p;i++){
		dp[0][i]=0;
	}
	for(int i=1;i<=n;i++){
		dp[i][0]=1e9;
		while((a[i]-mid)>=a[k+1]) k++;
		while((a[i]-2*mid)>=a[y+1]) y++;
		pre1[i]=k;
		pre2[i]=y;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=p;j++){
			int id=pre1[i];
			int id1=pre2[i];
			dp[i][j]=min(dp[id][j-1],dp[id1][j]+1);
			//cout << dp[i][j] << ' ' << i << ' ' << j << endl;
		}
	}
	if(dp[n][p]>q){
		l++;
	}
	mid=l,k=0,y=0;
	for(int i=1;i<=p;i++){
		dp[0][i]=0;
	}
	for(int i=1;i<=n;i++){
		dp[i][0]=1e9;
		while((a[i]-mid)>=a[k+1]) k++;
		while((a[i]-2*mid)>=a[y+1]) y++;
		pre1[i]=k;
		pre2[i]=y;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=p;j++){
			int id=pre1[i];
			int id1=pre2[i];
			dp[i][j]=min(dp[id][j-1],dp[id1][j]+1);
			//cout << dp[i][j] << ' ' << i << ' ' << j << endl;
		}
	}
	if(dp[n][p]>q){
		l++;
	}
	cout << l;
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:22:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   22 |   int mid=l+r>>1;
      |           ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 876 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 748 KB Output is correct
8 Correct 1 ms 748 KB Output is correct
9 Correct 1 ms 748 KB Output is correct
10 Correct 1 ms 748 KB Output is correct
11 Correct 1 ms 748 KB Output is correct
12 Correct 1 ms 748 KB Output is correct
13 Correct 1 ms 748 KB Output is correct
14 Correct 1 ms 748 KB Output is correct
15 Correct 1 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8428 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 9 ms 8556 KB Output is correct
8 Correct 18 ms 9324 KB Output is correct
9 Correct 72 ms 14316 KB Output is correct
10 Correct 156 ms 16108 KB Output is correct
11 Correct 15 ms 9068 KB Output is correct
12 Correct 92 ms 15980 KB Output is correct
13 Correct 8 ms 8556 KB Output is correct
14 Correct 9 ms 8556 KB Output is correct
15 Incorrect 9 ms 8556 KB Output isn't correct