Submission #673476

# Submission time Handle Problem Language Result Execution time Memory
673476 2022-12-20T16:41:32 Z S2speed Gap (APIO16_gap) C++17
100 / 100
46 ms 1864 KB
#include<bits/stdc++.h>
#include "gap.h"

using namespace std;

#pragma GCC optimize ("Ofast")

#define all(x) x.begin() , x.end()
#define sze(x) (ll)(x.size())
typedef long long ll;

const ll maxn = 1e5 + 17 , md = 1e9 + 7;

ll a[maxn] , mn , mx;

ll findGap(int T , int n){
	if(T == 1 || n <= 8){
		ll x = 0 , y = n , pn = 0 , px = 1e18;
		while(x < y){
			MinMax(pn , px , &mn , &mx);
			a[x++] = mn; a[--y] = mx;
			pn = mn + 1; px = mx - 1;
		}
		ll ans = 0;
		for(ll i = 0 ; i < n - 1 ; i++){
			ans = max(ans , a[i + 1] - a[i]);
		}
		return ans;
	}
	MinMax(0 , (ll)1e18 , &mn , &mx);
	ll ls = mx;
	ll cur = (mx - mn + n - 2) / (n - 1) , x = mn;
	while(ls - x > cur){
		ll l = x + 1 , r = x + cur;
		MinMax(l , r , &mn , &mx);
		if(mn != -1){
			x = mx;
			continue;
		}
		while(true){
			r = x + (cur << 1);
			MinMax(l , r , &mn , &mx);
			if(mn == -1){
				cur <<= 1;
			} else {
				cur = mn - x;
				x = mx;
				break;
			}
		}
	}
	return cur;
}
# 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 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 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 9 ms 592 KB Output is correct
17 Correct 8 ms 624 KB Output is correct
18 Correct 9 ms 592 KB Output is correct
19 Correct 9 ms 720 KB Output is correct
20 Correct 7 ms 592 KB Output is correct
21 Correct 38 ms 1804 KB Output is correct
22 Correct 39 ms 1860 KB Output is correct
23 Correct 42 ms 1864 KB Output is correct
24 Correct 37 ms 1856 KB Output is correct
25 Correct 37 ms 1864 KB Output is correct
26 Correct 42 ms 1840 KB Output is correct
27 Correct 35 ms 1852 KB Output is correct
28 Correct 44 ms 1840 KB Output is correct
29 Correct 36 ms 1816 KB Output is correct
30 Correct 29 ms 1736 KB Output is correct
31 Correct 0 ms 208 KB Output is correct
32 Correct 0 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 1 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 1 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 7 ms 432 KB Output is correct
17 Correct 6 ms 464 KB Output is correct
18 Correct 6 ms 504 KB Output is correct
19 Correct 8 ms 436 KB Output is correct
20 Correct 3 ms 464 KB Output is correct
21 Correct 29 ms 1084 KB Output is correct
22 Correct 23 ms 992 KB Output is correct
23 Correct 29 ms 1052 KB Output is correct
24 Correct 22 ms 1068 KB Output is correct
25 Correct 46 ms 1104 KB Output is correct
26 Correct 26 ms 980 KB Output is correct
27 Correct 26 ms 1068 KB Output is correct
28 Correct 23 ms 1064 KB Output is correct
29 Correct 29 ms 1068 KB Output is correct
30 Correct 12 ms 1044 KB Output is correct
31 Correct 0 ms 208 KB Output is correct
32 Correct 0 ms 208 KB Output is correct