Submission #337157

# Submission time Handle Problem Language Result Execution time Memory
337157 2020-12-18T16:30:44 Z CaroLinda Gap (APIO16_gap) C++14
100 / 100
76 ms 3296 KB
#include "gap.h"
#include <bits/stdc++.h>

#define all(x) x.begin(),x.end()
#define sz(x) (int)(x.size() )
#define ll long long 

const ll MAX = 1e18 ;

using namespace std ;

long long findGap(int T, int N)
{
	
	if( T == 1 || N <= 7 )
	{
		vector<ll> a(N) ;

		MinMax(0LL,MAX, &a[0] , &a[N-1] ) ;

		for(int l = 1 , r = N-2 ; l <= r ; l++ , r-- )
			MinMax(a[l-1]+1, a[r+1]-1, &a[l], &a[r] ) ;
		
		ll resp = -1LL ;

		for(int i = 0 ; i < N-1 ; i++ ) resp = max(resp, a[i+1]-a[i] ) ;

		return resp ; 

	}

	ll smallest, biggest, mn, mx ;

	MinMax(0, MAX, &smallest, &biggest ) ;

	ll d = (biggest-smallest-1)/(N-1) ;

	vector<ll> vec(1, smallest) ;

	int cnt = 0 ;

	for(ll l = smallest+1 ; l < biggest ; l += d+1 )
	{
		MinMax(l, min(l+d, biggest-1) , &mn, &mx) ;
		
		cnt++ ;

		if(mn == -1 ) continue ;

		vec.push_back(mn) ;
		vec.push_back(mx) ;

	}

	vec.push_back(biggest) ;

	d = 0LL ;

	for(int i = 0 ; i < vec.size() - 1 ; i++ ) d = max(d, vec[i+1]-vec[i] ) ;

	return d ;

}

Compilation message

gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:59:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |  for(int i = 0 ; i < vec.size() - 1 ; i++ ) d = max(d, vec[i+1]-vec[i] ) ;
      |                  ~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 13 ms 748 KB Output is correct
17 Correct 11 ms 748 KB Output is correct
18 Correct 11 ms 748 KB Output is correct
19 Correct 11 ms 748 KB Output is correct
20 Correct 9 ms 748 KB Output is correct
21 Correct 46 ms 1876 KB Output is correct
22 Correct 44 ms 1900 KB Output is correct
23 Correct 45 ms 1900 KB Output is correct
24 Correct 47 ms 2036 KB Output is correct
25 Correct 44 ms 1912 KB Output is correct
26 Correct 44 ms 1900 KB Output is correct
27 Correct 45 ms 1900 KB Output is correct
28 Correct 45 ms 2028 KB Output is correct
29 Correct 50 ms 1900 KB Output is correct
30 Correct 35 ms 1900 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 2 ms 364 KB Output is correct
14 Correct 2 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 16 ms 876 KB Output is correct
17 Correct 15 ms 1084 KB Output is correct
18 Correct 16 ms 876 KB Output is correct
19 Correct 15 ms 876 KB Output is correct
20 Correct 9 ms 588 KB Output is correct
21 Correct 63 ms 2276 KB Output is correct
22 Correct 62 ms 2276 KB Output is correct
23 Correct 69 ms 2276 KB Output is correct
24 Correct 63 ms 2276 KB Output is correct
25 Correct 59 ms 3296 KB Output is correct
26 Correct 69 ms 2284 KB Output is correct
27 Correct 63 ms 2276 KB Output is correct
28 Correct 63 ms 2276 KB Output is correct
29 Correct 76 ms 2276 KB Output is correct
30 Correct 37 ms 1516 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct