Submission #731935

# Submission time Handle Problem Language Result Execution time Memory
731935 2023-04-28T07:06:17 Z sentheta Gap (APIO16_gap) C++17
100 / 100
55 ms 3224 KB
#include "gap.h"
// author : sentheta aka vanwij
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cassert>
#include<random>
#include<chrono>
#include<cmath>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;

#define Int long long
#define V vector
#define pii pair<Int,Int>
#define ff first
#define ss second

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

#define pow2(x) (1LL<<(x))
#define msb(x) (63-__builtin_clzll(x))
#define bitcnt(x) (__builtin_popcountll(x))

#define nl '\n'
#define _ << ' ' <<
#define all(x) (x).begin(), (x).end()
#define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define dbg(x) if(1) cout << "?" << #x << " : " << (x) << endl << flush;

pii query(Int l,Int r){
	Int a, b;
	MinMax(l,r, &a,&b);
	return {a,b};
}
Int cdiv(Int a,Int b){
	return (a-1)/b+1;
}

int n;

Int findGap(int T,int _n){
	n = _n;
	if(T==1){
		V<Int> l, r;
		{
			auto[a,b] = query(0,1e18);
			l = {a};
			r = {b};
		}
		while((int)l.size() + (int)r.size() < n){
			auto[a,b] = query(l.back()+1, r.back()-1);
			l.push_back(a);
			r.push_back(b);
		}
		reverse(all(r));
		for(Int x : r) l.push_back(x);

		Int prv = l[0], ans = 0;
		for(Int x : l){
			ans = max(ans, x-prv);
			prv = x;
		}
		return ans;
	}

	auto[a1,an] = query(0,1e18);
	
	Int len = cdiv(an-a1, n-1)+1;
	V<Int> a = {a1};
	for(Int l=a1+1; l<an; l+=len){
		Int r = l+len;
		// Int r = min(an, l+len);
		auto[x,y] = query(l,r);
		
		if(x!=-1){
			a.push_back(x);
			a.push_back(y);
		}
	}
	a.push_back(an);

	Int ans = len-1;
	Int prv = a[0];
	for(Int x : a){
		ans = max(ans, x-prv);
		prv = x;
	}
	assert(ans >= cdiv(an-a1, n-1));
	return ans;
}
# 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 0 ms 208 KB Output is correct
5 Correct 1 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 10 ms 944 KB Output is correct
17 Correct 9 ms 1000 KB Output is correct
18 Correct 10 ms 992 KB Output is correct
19 Correct 9 ms 992 KB Output is correct
20 Correct 7 ms 976 KB Output is correct
21 Correct 40 ms 2572 KB Output is correct
22 Correct 39 ms 2540 KB Output is correct
23 Correct 37 ms 2544 KB Output is correct
24 Correct 38 ms 2628 KB Output is correct
25 Correct 35 ms 2620 KB Output is correct
26 Correct 40 ms 2580 KB Output is correct
27 Correct 38 ms 2540 KB Output is correct
28 Correct 38 ms 2636 KB Output is correct
29 Correct 43 ms 2628 KB Output is correct
30 Correct 30 ms 2656 KB Output is correct
31 Correct 0 ms 208 KB Output is correct
32 Correct 1 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 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 1 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 368 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 13 ms 904 KB Output is correct
17 Correct 13 ms 808 KB Output is correct
18 Correct 15 ms 828 KB Output is correct
19 Correct 13 ms 812 KB Output is correct
20 Correct 6 ms 464 KB Output is correct
21 Correct 55 ms 2172 KB Output is correct
22 Correct 55 ms 2184 KB Output is correct
23 Correct 53 ms 2180 KB Output is correct
24 Correct 54 ms 2212 KB Output is correct
25 Correct 49 ms 3224 KB Output is correct
26 Correct 53 ms 2184 KB Output is correct
27 Correct 54 ms 2188 KB Output is correct
28 Correct 55 ms 2244 KB Output is correct
29 Correct 53 ms 2248 KB Output is correct
30 Correct 27 ms 1480 KB Output is correct
31 Correct 0 ms 208 KB Output is correct
32 Correct 0 ms 208 KB Output is correct