답안 #351094

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
351094 2021-01-19T12:19:04 Z ladpro98 Gap (APIO16_gap) C++14
100 / 100
67 ms 1408 KB
#include <algorithm> 
#include "gap.h"
#include <iostream>
using namespace std;

const long long MAX_VALUE = 1000000000000000000LL;

long long task1(int n) {
    long long l = -1;
    long long r = MAX_VALUE + 1;
    long long res = 0;
    for (int i = 1; i <= (n + 1) / 2; ++i) {
        long long ll, rr;
        MinMax(l + 1, r - 1, &ll, &rr);
        if (i > 1) {
            res = max(res, ll - l);
            res = max(res, r - rr);
        }
        l = ll;
        r = rr;
    }
    res = max(res, r - l);
    return res;
}

long long task2(int n) {
    long long minimum;
    long long maximum;
    MinMax(0, MAX_VALUE, &minimum, &maximum);
    long long step = (maximum - minimum + n - 2) / (n - 1);
    long long res = step;
    long long last = minimum;
    for (long long v = minimum; v <= maximum; v += step + 1) {
        long long l, r;
        MinMax(v, v + step, &l, &r);
        if (l != -1) {
            res = max(res, l - last);
            last = r;
        }
    }
    return res;
}

long long findGap(int T, int N) {
    return T == 1 ? task1(N) : task2(N);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 13 ms 492 KB Output is correct
17 Correct 11 ms 492 KB Output is correct
18 Correct 12 ms 492 KB Output is correct
19 Correct 11 ms 492 KB Output is correct
20 Correct 10 ms 492 KB Output is correct
21 Correct 49 ms 1132 KB Output is correct
22 Correct 55 ms 1132 KB Output is correct
23 Correct 43 ms 1132 KB Output is correct
24 Correct 43 ms 1260 KB Output is correct
25 Correct 39 ms 1144 KB Output is correct
26 Correct 53 ms 1132 KB Output is correct
27 Correct 43 ms 1408 KB Output is correct
28 Correct 42 ms 1132 KB Output is correct
29 Correct 43 ms 1132 KB Output is correct
30 Correct 33 ms 1132 KB Output is correct
31 Correct 0 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 14 ms 620 KB Output is correct
17 Correct 17 ms 492 KB Output is correct
18 Correct 15 ms 492 KB Output is correct
19 Correct 15 ms 492 KB Output is correct
20 Correct 7 ms 480 KB Output is correct
21 Correct 67 ms 1132 KB Output is correct
22 Correct 67 ms 1144 KB Output is correct
23 Correct 62 ms 1172 KB Output is correct
24 Correct 60 ms 1132 KB Output is correct
25 Correct 54 ms 1132 KB Output is correct
26 Correct 61 ms 1176 KB Output is correct
27 Correct 61 ms 1132 KB Output is correct
28 Correct 62 ms 1260 KB Output is correct
29 Correct 60 ms 1132 KB Output is correct
30 Correct 31 ms 1140 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct