답안 #337151

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
337151 2020-12-18T15:59:29 Z CaroLinda Gap (APIO16_gap) C++14
100 / 100
53 ms 2028 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 cur = -1 ,mn=-1 , mx=-1 , biggest=-1 ;

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

	ll d = (biggest-cur+N)/N ;

	while( true )
	{

		if( cur + d > biggest ) return d ;				

		MinMax(cur+1, cur+d, &mn, &mx ) ;

		if( mx != -1 ) 
		{
			cur = mx ; 
			continue ;
		}

		ll l = cur+d+1, r = cur + (d<<1LL) ;

		while( true )
		{
			MinMax(l, min(r, biggest), &mn, &mx ) ;

			if( r >= biggest ) return ( mn == -1 ) ? d : (mn-cur) ;
		
			if( mn != -1 )
			{
				d = mn - cur ;
				cur = mn ;
				break ;
			}			

			ll auxL = r+1 ;
			ll auxR = cur+((r-cur)<<1LL );

			l = auxL ;
			r = auxR ;
	 	
		}
	}

	return d ;

}
# 결과 실행 시간 메모리 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 0 ms 364 KB Output is correct
5 Correct 1 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 384 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 11 ms 748 KB Output is correct
17 Correct 11 ms 768 KB Output is correct
18 Correct 11 ms 748 KB Output is correct
19 Correct 12 ms 748 KB Output is correct
20 Correct 8 ms 748 KB Output is correct
21 Correct 42 ms 1900 KB Output is correct
22 Correct 47 ms 1900 KB Output is correct
23 Correct 42 ms 1900 KB Output is correct
24 Correct 43 ms 2028 KB Output is correct
25 Correct 37 ms 1900 KB Output is correct
26 Correct 42 ms 1900 KB Output is correct
27 Correct 42 ms 1900 KB Output is correct
28 Correct 45 ms 1900 KB Output is correct
29 Correct 42 ms 1900 KB Output is correct
30 Correct 36 ms 2028 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 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 0 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 0 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 492 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 8 ms 492 KB Output is correct
17 Correct 8 ms 700 KB Output is correct
18 Correct 8 ms 492 KB Output is correct
19 Correct 8 ms 492 KB Output is correct
20 Correct 4 ms 492 KB Output is correct
21 Correct 28 ms 1132 KB Output is correct
22 Correct 29 ms 1232 KB Output is correct
23 Correct 28 ms 1132 KB Output is correct
24 Correct 28 ms 1132 KB Output is correct
25 Correct 53 ms 1364 KB Output is correct
26 Correct 28 ms 1132 KB Output is correct
27 Correct 28 ms 1132 KB Output is correct
28 Correct 29 ms 1132 KB Output is correct
29 Correct 29 ms 1124 KB Output is correct
30 Correct 15 ms 1132 KB Output is correct
31 Correct 0 ms 364 KB Output is correct
32 Correct 0 ms 364 KB Output is correct