답안 #753489

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
753489 2023-06-05T10:07:42 Z KN200711 Gap (APIO16_gap) C++14
100 / 100
46 ms 2632 KB
#include "gap.h"
# include <bits/stdc++.h>
# define ll long long
using namespace std;
ll solve2(int N) {
	ll lw = 0ll, hg = 0ll;
	MinMax(0ll, 1ll * 1e18, &lw, &hg);
	ll diff = hg - lw;
	diff = (diff + 1ll * N - 2ll) / (N - 1ll);
	
	ll ls = -1;
	while(lw < hg) {
		ll mn, mx;
		MinMax(lw, min(1ll * lw + 1ll * diff, (ll) 1e18), &mn, &mx);
		lw += diff + 1ll;
		if(mn == mx && mn == -1) continue;
		
		if(ls == -1) ls = mx;
		else {
			diff = max(diff, mn - ls);
			ls = mx;
		}
	}
	return diff;
}

long long findGap(int T, int N) {
	if(T == 2) return solve2(N);
	vector<ll> arr, arr1;
	arr.clear();
	arr1.clear();
	
	ll lw = 0ll, hg = 1e18;
	for(; (int) arr.size() + (int) arr1.size() < (int) N ;) {
		MinMax(lw, hg, &lw, &hg);
		if(lw != hg) {
			arr.push_back(lw);
			arr1.push_back(hg);
			lw++;
			hg--;
		} else {
			arr.push_back(lw);
		}
	}
	ll diff = 0ll;
	for(int c=arr1.size() - 1;c>=0;c--) {
		arr.push_back(arr1[c]);
	}
	for(int c=0;c + 1<(int) arr.size();c++) {
		diff = max(diff, arr[c + 1] - arr[c]);
	}
	return diff;
}


# 결과 실행 시간 메모리 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 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 2 ms 336 KB Output is correct
16 Correct 11 ms 956 KB Output is correct
17 Correct 10 ms 976 KB Output is correct
18 Correct 9 ms 940 KB Output is correct
19 Correct 9 ms 972 KB Output is correct
20 Correct 7 ms 976 KB Output is correct
21 Correct 41 ms 2628 KB Output is correct
22 Correct 37 ms 2620 KB Output is correct
23 Correct 36 ms 2544 KB Output is correct
24 Correct 35 ms 2628 KB Output is correct
25 Correct 35 ms 2632 KB Output is correct
26 Correct 46 ms 2548 KB Output is correct
27 Correct 38 ms 2592 KB Output is correct
28 Correct 35 ms 2628 KB Output is correct
29 Correct 40 ms 2596 KB Output is correct
30 Correct 33 ms 2540 KB Output is correct
31 Correct 0 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 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 1 ms 256 KB Output is correct
8 Correct 1 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 208 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 208 KB Output is correct
16 Correct 6 ms 464 KB Output is correct
17 Correct 7 ms 464 KB Output is correct
18 Correct 6 ms 432 KB Output is correct
19 Correct 5 ms 464 KB Output is correct
20 Correct 5 ms 468 KB Output is correct
21 Correct 26 ms 1088 KB Output is correct
22 Correct 21 ms 968 KB Output is correct
23 Correct 22 ms 1056 KB Output is correct
24 Correct 22 ms 1064 KB Output is correct
25 Correct 46 ms 1056 KB Output is correct
26 Correct 22 ms 1092 KB Output is correct
27 Correct 24 ms 1108 KB Output is correct
28 Correct 22 ms 1056 KB Output is correct
29 Correct 22 ms 960 KB Output is correct
30 Correct 21 ms 1020 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 1 ms 208 KB Output is correct