Submission #541095

# Submission time Handle Problem Language Result Execution time Memory
541095 2022-03-22T08:17:41 Z amunduzbaev Gap (APIO16_gap) C++17
100 / 100
58 ms 2244 KB
#include "bits/stdc++.h"
using namespace std;
#include "gap.h"
#ifndef EVAL
#include "grader.cpp"
#endif

#define ar array
typedef long long ll;
const ll inf = 1e18;

ll findGap(int t, int n){
	if(t == 1){
		ll l = 0, r = inf, mn, mx;
		vector<ll> a;
		for(int i=0;i<=n/2 && (int)a.size() < n;i++){
			MinMax(l, r, &mn, &mx);
			if(mn == -1) break;
			a.push_back(mn);
			a.push_back(mx);
			l = mn + 1, r = mx - 1;
		}
		
		sort(a.begin(), a.end());
		ll res = 0;
		for(int i=1;i<(int)a.size();i++){
			res = max(res, a[i] - a[i-1]);
		}
		
		return res;
	}
	
	ll l = 0, r = inf, mn, mx;
	MinMax(l, r, &mn, &mx);
	ll B = (mx - mn) / n, last = mn, R = mx;
	ll res = B, cnt = 0;
	
	for(l=mn+1;cnt<n;l=r+1){
		cnt++;
		r=l+B;
		MinMax(l, r, &mn, &mx);
		if(mn == -1 || mx == -1) continue;
		res = max(res, mn - last);
		last = mx;
	}
	
	res = max(res, R - last);
	return res;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 11 ms 848 KB Output is correct
17 Correct 12 ms 848 KB Output is correct
18 Correct 11 ms 848 KB Output is correct
19 Correct 11 ms 848 KB Output is correct
20 Correct 8 ms 848 KB Output is correct
21 Correct 42 ms 2204 KB Output is correct
22 Correct 45 ms 2224 KB Output is correct
23 Correct 45 ms 2204 KB Output is correct
24 Correct 43 ms 2240 KB Output is correct
25 Correct 38 ms 2244 KB Output is correct
26 Correct 49 ms 2240 KB Output is correct
27 Correct 47 ms 2244 KB Output is correct
28 Correct 39 ms 2176 KB Output is correct
29 Correct 42 ms 2200 KB Output is correct
30 Correct 34 ms 2164 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 0 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 13 ms 464 KB Output is correct
17 Correct 13 ms 464 KB Output is correct
18 Correct 14 ms 464 KB Output is correct
19 Correct 14 ms 500 KB Output is correct
20 Correct 9 ms 440 KB Output is correct
21 Correct 58 ms 1068 KB Output is correct
22 Correct 55 ms 1084 KB Output is correct
23 Correct 51 ms 1080 KB Output is correct
24 Correct 57 ms 1080 KB Output is correct
25 Correct 46 ms 1080 KB Output is correct
26 Correct 52 ms 1080 KB Output is correct
27 Correct 53 ms 1180 KB Output is correct
28 Correct 58 ms 968 KB Output is correct
29 Correct 52 ms 1056 KB Output is correct
30 Correct 32 ms 1064 KB Output is correct
31 Correct 0 ms 208 KB Output is correct
32 Correct 0 ms 208 KB Output is correct