답안 #254853

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
254853 2020-07-30T18:04:10 Z maximath_1 Gap (APIO16_gap) C++11
100 / 100
72 ms 1960 KB
/*
	* APIO 2016 Gap

	* T = 1
	> Two pointers, left right approaching the center

	* T = 2
	> pigeon hole principle
	> get minimum and maximum, 
	> then divide the array into n - 1 approx. equal parts
	> By PHP, one of these parts will be empty
	> Thus, maximum gap >= the length of a part
	> Now we can simply compare with seg[i].left - seg[i - 1].right
*/
#include "gap.h"
#include <iostream>
using namespace std;

#define ll long long
const ll mn = 0ll, mx = 1e18;

ll res = mn, arr[100005];

ll findGap(int t, int n){
	if(t == 1){
		ll lf = mn, rg = mx, k = 0;
		for(int i = n; i > 0; i -= 2){
			MinMax(lf, rg, &arr[k], &arr[n - 1 - k]);
			lf = arr[k] + 1;
			rg = arr[n - 1 - k] - 1;
			k ++;
		}

		for(int i = 1; i < n; i ++)
			res = max(res, arr[i] - arr[i - 1]);
	}
	if(t == 2){
		ll lf, rg;
		MinMax(mn, mx, &lf, &rg);

		if(n == 2) return rg - lf;
		ll len = rg - lf - 1ll;	
		ll st = lf + 1, ed = lf;

		for(int i = 0; i < n - 1; i ++){
			ll e = st + len / (n - 1) - 1;
			if(i < len % (n - 1)) e ++;
			MinMax(st, e, &lf, &rg);

			if(lf != -1){
				res = max(res, lf - ed);
				ed = rg;
			}
			st = e + 1ll;
		}
		res = max(res, st - ed);
	}
	return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 13 ms 760 KB Output is correct
17 Correct 12 ms 768 KB Output is correct
18 Correct 15 ms 768 KB Output is correct
19 Correct 12 ms 768 KB Output is correct
20 Correct 9 ms 768 KB Output is correct
21 Correct 49 ms 1912 KB Output is correct
22 Correct 50 ms 1912 KB Output is correct
23 Correct 50 ms 1840 KB Output is correct
24 Correct 50 ms 1912 KB Output is correct
25 Correct 41 ms 1912 KB Output is correct
26 Correct 53 ms 1960 KB Output is correct
27 Correct 50 ms 1912 KB Output is correct
28 Correct 52 ms 1940 KB Output is correct
29 Correct 56 ms 1916 KB Output is correct
30 Correct 38 ms 1912 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 16 ms 512 KB Output is correct
17 Correct 16 ms 512 KB Output is correct
18 Correct 16 ms 512 KB Output is correct
19 Correct 16 ms 512 KB Output is correct
20 Correct 8 ms 512 KB Output is correct
21 Correct 66 ms 1064 KB Output is correct
22 Correct 66 ms 1144 KB Output is correct
23 Correct 65 ms 1056 KB Output is correct
24 Correct 66 ms 1144 KB Output is correct
25 Correct 58 ms 1060 KB Output is correct
26 Correct 65 ms 1176 KB Output is correct
27 Correct 65 ms 1144 KB Output is correct
28 Correct 72 ms 1144 KB Output is correct
29 Correct 66 ms 1148 KB Output is correct
30 Correct 36 ms 1168 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct