Submission #542400

# Submission time Handle Problem Language Result Execution time Memory
542400 2022-03-26T12:11:56 Z farhan132 Gap (APIO16_gap) C++17
100 / 100
77 ms 5768 KB
#include "gap.h"
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<ll> vll;
typedef pair<ll , ll> ii;
typedef vector< ii > vii;
typedef pair < pair < ll , ll > , pair < ll , ll > > cm; 
typedef tuple < int, ll, ll > tp;
 
#define ff first
#define ss second
#define pb push_back
#define in insert

ii get(ll x, ll y){
	ll mn , mx;
	MinMax(x, y, &mn, &mx);
	return {mn, mx};
}

long long findGap(int T, int n)
{   
	if(T == 1){
		set < ll > s;
		ll L = 0, R = 1e18;
		while(L <= R && s.size() < n){
			auto [l , r] = get(L , R);
			if(l == -1) break;
			s.in(l);
			s.in(r);
			L = l + 1;
			R = r - 1;
		}
		ll last = -1 , ans = 0;
		for(auto u : s){
			if(last != -1) ans = max(ans , u - last); last = u;
		}
		return ans;
	}
	auto [l, r] = get(0, 1e18);
	if(r - l + 1 == n) return 1;
	ll block = (((r - l + 1) - n) + n - 2) / (n - 1);
	vector < ii > v;
	ll cur = l + 1;
	ll last = l;
	ll ans = block + 1;
	while(cur <= r){
		ll L = cur , R = min(cur + block, r);
		auto [x, y] = get(L , R);
		cur = R + 1;
		if(x == -1){
			continue;
		}
		if(last != -1) ans = max(ans , x - last);
		last = y;
	}
	return ans;
}

Compilation message

gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:31:28: warning: comparison of integer expressions of different signedness: 'std::set<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   31 |   while(L <= R && s.size() < n){
      |                   ~~~~~~~~~^~~
gap.cpp:41:4: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   41 |    if(last != -1) ans = max(ans , u - last); last = u;
      |    ^~
gap.cpp:41:46: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   41 |    if(last != -1) ans = max(ans , u - last); last = u;
      |                                              ^~~~
# 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 1 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 1 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 1 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 13 ms 1588 KB Output is correct
17 Correct 13 ms 1616 KB Output is correct
18 Correct 13 ms 1580 KB Output is correct
19 Correct 14 ms 1616 KB Output is correct
20 Correct 12 ms 1572 KB Output is correct
21 Correct 55 ms 5720 KB Output is correct
22 Correct 66 ms 5756 KB Output is correct
23 Correct 77 ms 5716 KB Output is correct
24 Correct 55 ms 5664 KB Output is correct
25 Correct 51 ms 5768 KB Output is correct
26 Correct 59 ms 5760 KB Output is correct
27 Correct 59 ms 5668 KB Output is correct
28 Correct 54 ms 5672 KB Output is correct
29 Correct 56 ms 5672 KB Output is correct
30 Correct 48 ms 5668 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 0 ms 208 KB Output is correct
2 Correct 0 ms 252 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 1 ms 256 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 324 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 12 ms 464 KB Output is correct
17 Correct 12 ms 512 KB Output is correct
18 Correct 14 ms 464 KB Output is correct
19 Correct 16 ms 520 KB Output is correct
20 Correct 8 ms 464 KB Output is correct
21 Correct 56 ms 1036 KB Output is correct
22 Correct 51 ms 1088 KB Output is correct
23 Correct 53 ms 1048 KB Output is correct
24 Correct 55 ms 956 KB Output is correct
25 Correct 57 ms 1080 KB Output is correct
26 Correct 50 ms 1108 KB Output is correct
27 Correct 49 ms 1080 KB Output is correct
28 Correct 49 ms 1000 KB Output is correct
29 Correct 56 ms 1080 KB Output is correct
30 Correct 28 ms 1040 KB Output is correct
31 Correct 0 ms 208 KB Output is correct
32 Correct 0 ms 208 KB Output is correct