Submission #750837

# Submission time Handle Problem Language Result Execution time Memory
750837 2023-05-30T11:16:17 Z PoPularPlusPlus Gap (APIO16_gap) C++17
100 / 100
64 ms 2268 KB
#include "gap.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long 
#define pb(e) push_back(e)
#define sv(a) sort(a.begin(),a.end())
#define sa(a,n) sort(a,a+n)
#define mp(a,b) make_pair(a,b)
#define vf first
#define vs second
#define ar array
#define all(x) x.begin(),x.end()

long long findGap(int t, int n)
{
	if(t == 1){
		ll arr[n];
		memset(arr,0,sizeof arr);
		ll l = 0 , r = 1000000000000000000;
		int i = 0 , j = n - 1;
		while(i <= j){
			MinMax(l , r , &arr[i] , &arr[j]);
			assert(arr[i] != -1);
			assert(arr[j] != -1);
			l = arr[i]+1;
			r = arr[j]-1;
			i++;
			j--;
		}
		ll ans = 0;
		for(i = 0; i < n-1; i++){
			ans = max(ans , arr[i+1]-arr[i]);
		}
		return ans;
	}
	vector<ll> v;
	ll mn , mx;
	MinMax(0,1e18,&mn,&mx);
	if(n == 2)return mx - mn;
	v.pb(mn);
	ll range = (mx - 1) - (mn + 1) + 1;
	ll div = range/(n-1);
	ll rem = range % (n - 1);
	ll cur = mn+1;
	for(ll i = 0; i < n - 1; i++){
		ll add = 0;
		if(rem < i)add = 1;
		ll x , y;
		ll r = cur + div + add - 1;
		MinMax(cur , r , &x , &y);
		if(x != -1){
			v.pb(x);
			if(x != y)v.pb(y);
		}
		cur = r + 1;
	}
	v.pb(mx);
	ll ans = 0;
	for(int i = 0; i < v.size()-1; i++){
		ans = max(ans , v[i+1]-v[i]);
	}
	return ans;
}

Compilation message

gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:60:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |  for(int i = 0; i < v.size()-1; i++){
      |                 ~~^~~~~~~~~~~~
# 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 1 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 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 9 ms 644 KB Output is correct
17 Correct 9 ms 704 KB Output is correct
18 Correct 12 ms 592 KB Output is correct
19 Correct 9 ms 684 KB Output is correct
20 Correct 7 ms 592 KB Output is correct
21 Correct 35 ms 1824 KB Output is correct
22 Correct 35 ms 1824 KB Output is correct
23 Correct 44 ms 1748 KB Output is correct
24 Correct 36 ms 1828 KB Output is correct
25 Correct 32 ms 1860 KB Output is correct
26 Correct 35 ms 1828 KB Output is correct
27 Correct 39 ms 1956 KB Output is correct
28 Correct 35 ms 1828 KB Output is correct
29 Correct 37 ms 1872 KB Output is correct
30 Correct 27 ms 1872 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 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 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 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 12 ms 848 KB Output is correct
17 Correct 13 ms 848 KB Output is correct
18 Correct 13 ms 848 KB Output is correct
19 Correct 16 ms 876 KB Output is correct
20 Correct 6 ms 464 KB Output is correct
21 Correct 64 ms 2176 KB Output is correct
22 Correct 50 ms 2240 KB Output is correct
23 Correct 51 ms 2240 KB Output is correct
24 Correct 51 ms 2200 KB Output is correct
25 Correct 49 ms 2240 KB Output is correct
26 Correct 56 ms 2136 KB Output is correct
27 Correct 55 ms 2224 KB Output is correct
28 Correct 57 ms 2240 KB Output is correct
29 Correct 56 ms 2268 KB Output is correct
30 Correct 26 ms 1332 KB Output is correct
31 Correct 0 ms 208 KB Output is correct
32 Correct 1 ms 208 KB Output is correct