Submission #578765

# Submission time Handle Problem Language Result Execution time Memory
578765 2022-06-17T22:46:29 Z MohamedAhmed04 Gap (APIO16_gap) C++14
100 / 100
70 ms 3168 KB
#include "gap.h"
#include <bits/stdc++.h>

using namespace std ;

long long solve1(int N)
{
	long long L = 1 , R = 1e18 ;
	vector<long long>v ;
	while(N > 0)
	{
		long long x , y ;
		MinMax(L , R , &x , &y) ;
		if(x == -1)
			break ;
		N -= 2 ;
		v.push_back(x) , v.push_back(y) ;
		L = x+1 , R = y-1 ;
	}
	sort(v.begin() , v.end()) ;
	long long ans = 0 ;
	int sz = v.size() ;
	for(int i = 1 ; i < sz ; ++i)
		ans = max(ans , v[i] - v[i-1]) ;
	return ans ;
}

long long solve2(int N)
{
	long long L , R ;
	MinMax(1 , 1e18 , &L , &R) ;
	long long sz = (R-L+1 + N-1) / N ;
	vector<long long>v ;
	v.push_back(L) ;
	for(long long i = L ; i < R ; i += sz)
	{
		long long l = max(i , L+1) , r = min(i+sz-1 , R-1) ;
		if(l > r)
			continue ;
		long long x , y ;
		MinMax(l , r , &x , &y) ;
		if(x != -1 && y != -1)
			v.push_back(x) , v.push_back(y) ;
	}
	v.push_back(R) ;
	sz = v.size() ;
	long long ans = 0 ;
	for(int i = 1 ; i < sz ; ++i)
		ans = max(ans , v[i] - v[i-1]) ;
	return ans ;
}

long long findGap(int T, int N)
{
	if(T == 1)
		return solve1(N) ;
	else
		return solve2(N) ;
}
# 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 0 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 2 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 812 KB Output is correct
17 Correct 12 ms 848 KB Output is correct
18 Correct 11 ms 848 KB Output is correct
19 Correct 12 ms 808 KB Output is correct
20 Correct 12 ms 880 KB Output is correct
21 Correct 50 ms 2208 KB Output is correct
22 Correct 53 ms 2176 KB Output is correct
23 Correct 41 ms 2244 KB Output is correct
24 Correct 47 ms 2188 KB Output is correct
25 Correct 38 ms 2336 KB Output is correct
26 Correct 54 ms 2184 KB Output is correct
27 Correct 55 ms 2144 KB Output is correct
28 Correct 41 ms 2200 KB Output is correct
29 Correct 43 ms 2200 KB Output is correct
30 Correct 37 ms 2220 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 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 1 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 13 ms 848 KB Output is correct
17 Correct 13 ms 848 KB Output is correct
18 Correct 13 ms 812 KB Output is correct
19 Correct 16 ms 852 KB Output is correct
20 Correct 8 ms 592 KB Output is correct
21 Correct 60 ms 2208 KB Output is correct
22 Correct 70 ms 2288 KB Output is correct
23 Correct 70 ms 2196 KB Output is correct
24 Correct 68 ms 2240 KB Output is correct
25 Correct 56 ms 3168 KB Output is correct
26 Correct 61 ms 2228 KB Output is correct
27 Correct 61 ms 2200 KB Output is correct
28 Correct 61 ms 2236 KB Output is correct
29 Correct 64 ms 2220 KB Output is correct
30 Correct 30 ms 1468 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 1 ms 208 KB Output is correct