Submission #95124

# Submission time Handle Problem Language Result Execution time Memory
95124 2019-01-27T14:07:05 Z mhnd Watching (JOI13_watching) C++14
0 / 100
4 ms 376 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int N = 1e5+50;
const int M = 1e6;
const ll oo = 1e18;
const int mod = 1e9+7;

vector<int> a;
int n,p,q;

bool can(int w){
	int s = p,b = q;
	for(int i=0;i<n;i++){
		int md,lo=i,hi=n-1,f = -1;
		while(lo <= hi){
			int md = (lo+hi)/2;
			if(a[md] - a[i] + 1 <= 2*w){
				lo = md+1;
				f = md;
			}else hi = md-1;
		}
		lo = i;hi=n-1;
		int f2 = -1;
		while(lo <= hi){
			int md = (lo+hi)/2;
			if(a[md] - a[i] + 1 <= w){
				lo = md+1;
				f2 = md;
			}else hi = md-1;
		}
		if(!s && !b)return 0;
		if(!s){
			if(f == -1)return 0;
			b--;
			i = f;
		}else if(!b){
			if(f2 == -1)return 0;
			s--;
			i = f2;
		}else if(f == f2){
			if(f2 == -1)return 0;
			s--;
			i = f2;
		}else{
			if(f == -1)return 0;
			b--;
			i = f;
		}
		if(i == n-1)return 1;
	}
	return 0;
}

int main(){
	#ifndef ONLINE_JUDGE
		// freopen("input.txt","r",stdin);
	#endif
	cin>>n>>p>>q;
	a.resize(n);
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a.begin(),a.end());
	ll md,lo=0,hi=1e9,ans = 1e9;
	while(lo <= hi){
		md = (lo+hi)/2;
		if(can(md)){
			hi = md-1;
			ans = md;
		}else lo = md+1;
	}
	cout << ans << endl;
}

Compilation message

watching.cpp: In function 'bool can(int)':
watching.cpp:19:7: warning: unused variable 'md' [-Wunused-variable]
   int md,lo=i,hi=n-1,f = -1;
       ^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 0 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Incorrect 2 ms 376 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
4 Correct 4 ms 376 KB Output is correct
5 Correct 4 ms 376 KB Output is correct
6 Correct 4 ms 376 KB Output is correct
7 Incorrect 3 ms 376 KB Output isn't correct
8 Halted 0 ms 0 KB -