답안 #249365

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
249365 2020-07-14T16:54:16 Z sahil_k Gap (APIO16_gap) C++14
100 / 100
85 ms 1272 KB
#include "gap.h"
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
long long findGap (int t, int n) {
	if (t == 1) {
		long long mn, mx;
		MinMax(0, 1e18, &mn, &mx);
		long long p_mn = mn, p_mx = mx;
		long long ans = 0;
		for (int i=1; i<(n+1)/2; i++) {
			MinMax(p_mn+1, p_mx-1, &mn, &mx);
			ans = max(ans, mn-p_mn);
			ans = max(ans, p_mx-mx);
			p_mn = mn;
			p_mx = mx;
		}
		ans = max(ans, mx-mn);
		return ans;
	} else {
		long long mn, mx;
		MinMax(0, 1e18, &mn, &mx);
		if (n == 2) return mx-mn;
		long long sz = (mx-mn-1+n)/n;
		long long prev = mn;
		long long pos = mn+1;
		long long ans = 0;
		for (long long i=0; i<n; i++) {
			if (pos <= pos+sz-1) MinMax(pos, pos+sz-1, &mn, &mx);
			if (mn > -1) {
				ans = max(ans, mn-prev);
				prev = mx;
			}
			pos += sz;
		}
		return max(ans, mx-prev);
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 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 0 ms 384 KB Output is correct
10 Correct 0 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 416 KB Output is correct
16 Correct 13 ms 508 KB Output is correct
17 Correct 14 ms 512 KB Output is correct
18 Correct 17 ms 512 KB Output is correct
19 Correct 14 ms 512 KB Output is correct
20 Correct 9 ms 512 KB Output is correct
21 Correct 55 ms 1144 KB Output is correct
22 Correct 50 ms 1132 KB Output is correct
23 Correct 53 ms 1136 KB Output is correct
24 Correct 49 ms 1144 KB Output is correct
25 Correct 42 ms 1152 KB Output is correct
26 Correct 48 ms 1156 KB Output is correct
27 Correct 57 ms 1144 KB Output is correct
28 Correct 51 ms 1152 KB Output is correct
29 Correct 57 ms 1144 KB Output is correct
30 Correct 37 ms 1144 KB Output is correct
31 Correct 0 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 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 0 ms 384 KB Output is correct
10 Correct 0 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 16 ms 512 KB Output is correct
17 Correct 16 ms 512 KB Output is correct
18 Correct 18 ms 512 KB Output is correct
19 Correct 16 ms 512 KB Output is correct
20 Correct 11 ms 512 KB Output is correct
21 Correct 70 ms 1152 KB Output is correct
22 Correct 77 ms 1144 KB Output is correct
23 Correct 85 ms 1144 KB Output is correct
24 Correct 65 ms 1144 KB Output is correct
25 Correct 56 ms 1104 KB Output is correct
26 Correct 73 ms 1144 KB Output is correct
27 Correct 64 ms 1144 KB Output is correct
28 Correct 77 ms 1272 KB Output is correct
29 Correct 66 ms 1272 KB Output is correct
30 Correct 34 ms 1152 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 0 ms 384 KB Output is correct