답안 #456448

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
456448 2021-08-06T18:43:01 Z nonsensenonsense1 Gap (APIO16_gap) C++17
100 / 100
68 ms 1088 KB
#include "gap.h"
#include <algorithm>

const long long N = 1000000000000000000;

long long task1(int n) 
{
	long long l = 0, r = N, ans = 0;
	for (int i = 0; i * 2 < n; ++i) {
		long long ll, rr;
		MinMax(l, r, &ll, &rr);
		if (l) ans = std::max(ans, ll - l + 1);
		if (r != N) ans = std::max(ans, r - rr + 1);
		if (i * 2 == n - 2) ans = std::max(ans, rr - ll);
		l = ll + 1;
		r = rr - 1;
	}
	return ans;
}

inline long long d(int n, int k, long long l, long long r) 
{
	return l + (__int128)(r - l) * k / n;
}

long long task2(int n) 
{
	long long l, r;
	MinMax(0, N, &l, &r);
	if (n == 2) return r - l;
	++l;
	long long pr = l - 1, ans = 0, len = d(n - 2, 1, l, r) - d(n - 2, 0, l, r);
	for (int i = 0; i < n - 2; ++i) {
		long long ll, rr;
		MinMax(d(n - 2, i, l, r), d(n - 2, i + 1, l, r) - 1, &ll, &rr);
		if (ll != -1) {
			ans = std::max(ans, ll - pr);
			pr = rr;
		}
	}
	return std::max(ans, r - pr);
}

long long findGap(int t, int n) 
{
	if (t == 1) return task1(n);
	return task2(n);
}

Compilation message

gap.cpp: In function 'long long int task2(int)':
gap.cpp:32:33: warning: unused variable 'len' [-Wunused-variable]
   32 |  long long pr = l - 1, ans = 0, len = d(n - 2, 1, l, r) - d(n - 2, 0, l, r);
      |                                 ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 200 KB Output is correct
4 Correct 0 ms 200 KB Output is correct
5 Correct 0 ms 200 KB Output is correct
6 Correct 0 ms 200 KB Output is correct
7 Correct 0 ms 200 KB Output is correct
8 Correct 0 ms 200 KB Output is correct
9 Correct 1 ms 200 KB Output is correct
10 Correct 0 ms 200 KB Output is correct
11 Correct 1 ms 200 KB Output is correct
12 Correct 1 ms 200 KB Output is correct
13 Correct 1 ms 200 KB Output is correct
14 Correct 1 ms 200 KB Output is correct
15 Correct 1 ms 200 KB Output is correct
16 Correct 11 ms 456 KB Output is correct
17 Correct 10 ms 456 KB Output is correct
18 Correct 12 ms 384 KB Output is correct
19 Correct 11 ms 452 KB Output is correct
20 Correct 8 ms 456 KB Output is correct
21 Correct 46 ms 1052 KB Output is correct
22 Correct 43 ms 1048 KB Output is correct
23 Correct 43 ms 1036 KB Output is correct
24 Correct 43 ms 1056 KB Output is correct
25 Correct 38 ms 1044 KB Output is correct
26 Correct 47 ms 1080 KB Output is correct
27 Correct 43 ms 1064 KB Output is correct
28 Correct 43 ms 968 KB Output is correct
29 Correct 42 ms 960 KB Output is correct
30 Correct 34 ms 968 KB Output is correct
31 Correct 0 ms 200 KB Output is correct
32 Correct 0 ms 200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 0 ms 200 KB Output is correct
3 Correct 1 ms 200 KB Output is correct
4 Correct 0 ms 200 KB Output is correct
5 Correct 0 ms 200 KB Output is correct
6 Correct 0 ms 200 KB Output is correct
7 Correct 0 ms 200 KB Output is correct
8 Correct 0 ms 200 KB Output is correct
9 Correct 0 ms 200 KB Output is correct
10 Correct 0 ms 200 KB Output is correct
11 Correct 1 ms 200 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 200 KB Output is correct
14 Correct 1 ms 200 KB Output is correct
15 Correct 1 ms 200 KB Output is correct
16 Correct 14 ms 528 KB Output is correct
17 Correct 16 ms 488 KB Output is correct
18 Correct 15 ms 456 KB Output is correct
19 Correct 15 ms 456 KB Output is correct
20 Correct 8 ms 456 KB Output is correct
21 Correct 68 ms 1028 KB Output is correct
22 Correct 67 ms 960 KB Output is correct
23 Correct 62 ms 1088 KB Output is correct
24 Correct 60 ms 1040 KB Output is correct
25 Correct 57 ms 960 KB Output is correct
26 Correct 62 ms 1052 KB Output is correct
27 Correct 61 ms 960 KB Output is correct
28 Correct 68 ms 1044 KB Output is correct
29 Correct 61 ms 996 KB Output is correct
30 Correct 34 ms 1036 KB Output is correct
31 Correct 0 ms 200 KB Output is correct
32 Correct 0 ms 200 KB Output is correct