답안 #365292

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
365292 2021-02-11T11:43:34 Z Bill_00 구경하기 (JOI13_watching) C++14
0 / 100
11 ms 8428 KB
#include <bits/stdc++.h>
using namespace std;
int a[2001];
int dp[2001][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>=n || q>=n || p+q>=n){
		cout << 1;
		return 0;
	}
	int l=1,r=1000000000,res;
	while(l!=r){
		for(int i=1;i<=p;i++){
			dp[0][i]=0;
		}
		for(int i=1;i<=n;i++){
			dp[i][0]=1e9;
		}
		int mid=l+r>>1;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=p;j++){
				int b=a[i]-mid+1;
				int id=lower_bound((a+1),(a+n+1),b)-(a+1);
				b=a[i]-2*mid+1;
				int id1=lower_bound((a+1),(a+n+1),b)-(a+1);
				dp[i][j]=min(dp[id][j-1],dp[id1][j]+1);
			}
		}
		if(dp[n][p]>q){
			l=mid+1;
		}
		else{
          	res=mid;
          	r=mid-1;
        }
	}
	cout << res;
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:27:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   27 |   int mid=l+r>>1;
      |           ~^~
watching.cpp:45:10: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
   45 |  cout << res;
      |          ^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 896 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 8428 KB Output isn't correct
2 Halted 0 ms 0 KB -