Submission #553190

# Submission time Handle Problem Language Result Execution time Memory
553190 2022-04-25T03:29:30 Z Gurban Watching (JOI13_watching) C++17
100 / 100
227 ms 16036 KB
#include "bits/stdc++.h"
using namespace std;

using ll = long long;

const int maxn=2e3+5;
int n,p,q;
int a[maxn];
int dp[maxn][maxn];

bool check(int w){
	for(int i = 0;i <= n;i++) for(int j = 0;j <= q;j++) dp[i][j] = 1e9;
	dp[0][0] = 0;
	int pos = 1;
	int idx = 1;
	for(int i = 1;i <= n;i++){
		while(a[i] - w >= a[pos]) pos++;
		while(a[i] - 2*w >= a[idx]) idx++;
		for(int j = 0;j <= q;j++){
			if(j) dp[i][j] = dp[idx-1][j-1];
			dp[i][j] = min(dp[i][j],dp[pos-1][j] + 1);
		}
	}
	bool tr = 0;
	for(int i = 0;i <= q;i++) tr |= (dp[n][i] <= p);
	return tr;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> n >> p >> q;
	for(int i = 1;i <= n;i++) cin >> a[i];
	if(p + q >= n) return cout<<1,0;
	sort(a + 1,a + n + 1);
	
	int l = 1,r = 1e9,md,ans;
	while(l <= r){
		md = (l + r) >> 1;
		if(check(md)) ans=md,r=md-1;
		else l=md+1;
	}
	cout<<ans;
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:44:8: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   44 |  cout<<ans;
      |        ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 724 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 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 324 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 712 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 712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8280 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 340 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 5 ms 8400 KB Output is correct
8 Correct 93 ms 14248 KB Output is correct
9 Correct 20 ms 9300 KB Output is correct
10 Correct 15 ms 9140 KB Output is correct
11 Correct 227 ms 16036 KB Output is correct
12 Correct 135 ms 16024 KB Output is correct
13 Correct 6 ms 8404 KB Output is correct
14 Correct 5 ms 8404 KB Output is correct
15 Correct 6 ms 8404 KB Output is correct