답안 #753713

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
753713 2023-06-05T18:19:47 Z denniskim Gap (APIO16_gap) C++17
100 / 100
65 ms 2256 KB
#include "gap.h"
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef __int128 lll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
#define MAX 9223372036854775807LL
#define MIN -9223372036854775807LL
#define INF 0x3f3f3f3f3f3f3f3f
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout << fixed; cout.precision(10);
#define sp << " "
#define en << "\n"
#define compress(v) sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end())

ll findGap(int T, int N)
{
	ll mini, maxi;
	
	if(T == 1)
	{
		vector<ll> vec;
		ll l = 0, r = 1000000000000000000LL;
		
		while(1)
		{
			MinMax(l, r, &mini, &maxi);
			
			if(mini == -1)
				break;
			
			if(mini == maxi)
			{
				vec.push_back(mini);
				break;
			}
			
			vec.push_back(mini);
			vec.push_back(maxi);
			
			l = mini + 1;
			r = maxi - 1;
			
			if((ll)vec.size() == N)
				break;
		}
		
		sort(vec.begin(), vec.end());
		
		ll ans = 0;
		
		for(ll i = 1 ; i < N ; i++)
			ans = max(ans, vec[i] - vec[i - 1]);
		
		return ans;
	}
	
	vector<ll> vec;
	ll l = 0, r = 1000000000000000000;
	
	MinMax(l, r, &mini, &maxi);
	
	l = mini;
	r = maxi;
	
	vec.push_back(l);
	vec.push_back(r);
	
	ll rng = (r - l + N - 2) / (N - 1);
	ll L = l;
	
	while(1)
	{
		L++;
		ll R = min(r, L + rng - 1);
		
		if(L > R)
			break;
		
		MinMax(L, R, &mini, &maxi);
		
		if(mini != -1)
		{
			if(mini == maxi)
				vec.push_back(mini);
			
			else
			{
				vec.push_back(mini);
				vec.push_back(maxi);
			}
		}
		
		if(R == r)
			break;
		
		L = R;
	}
	
	sort(vec.begin(), vec.end());
	
	ll ans = 0;
	
	for(ll i = 1 ; i < (ll)vec.size() ; i++)
		ans = max(ans, vec[i] - vec[i - 1]);
	
	return ans;
}
# 결과 실행 시간 메모리 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 1 ms 244 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 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 11 ms 900 KB Output is correct
17 Correct 11 ms 868 KB Output is correct
18 Correct 11 ms 848 KB Output is correct
19 Correct 11 ms 808 KB Output is correct
20 Correct 11 ms 836 KB Output is correct
21 Correct 45 ms 2204 KB Output is correct
22 Correct 43 ms 2204 KB Output is correct
23 Correct 43 ms 2232 KB Output is correct
24 Correct 46 ms 2200 KB Output is correct
25 Correct 38 ms 2200 KB Output is correct
26 Correct 45 ms 2184 KB Output is correct
27 Correct 40 ms 2240 KB Output is correct
28 Correct 43 ms 2184 KB Output is correct
29 Correct 40 ms 2240 KB Output is correct
30 Correct 35 ms 2256 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 0 ms 208 KB Output is correct
# 결과 실행 시간 메모리 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 1 ms 208 KB Output is correct
5 Correct 1 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 0 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 12 ms 848 KB Output is correct
17 Correct 14 ms 852 KB Output is correct
18 Correct 13 ms 872 KB Output is correct
19 Correct 13 ms 848 KB Output is correct
20 Correct 7 ms 464 KB Output is correct
21 Correct 53 ms 2160 KB Output is correct
22 Correct 65 ms 2192 KB Output is correct
23 Correct 54 ms 2208 KB Output is correct
24 Correct 53 ms 2236 KB Output is correct
25 Correct 57 ms 2180 KB Output is correct
26 Correct 55 ms 2200 KB Output is correct
27 Correct 55 ms 2216 KB Output is correct
28 Correct 53 ms 2204 KB Output is correct
29 Correct 58 ms 2196 KB Output is correct
30 Correct 31 ms 1480 KB Output is correct
31 Correct 0 ms 208 KB Output is correct
32 Correct 0 ms 208 KB Output is correct