답안 #102815

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
102815 2019-03-27T15:56:47 Z alexpetrescu Gap (APIO16_gap) C++14
100 / 100
80 ms 2296 KB
#include <algorithm>
#include <vector>

#include "gap.h"

long long findGap(int T, int N) {
    long long R = 1000000000000000000LL;
    if (T == 1) {
        long long a = 0, b = R;
        int cnt = 0;
        std::vector < long long > ans;
        while (a <= b && cnt < (N + 1) / 2) {
            cnt++;
            long long x, y;
            MinMax(a, b, &x, &y);
            if (x != -1)
                ans.push_back(x), ans.push_back(y);
            a = x + 1;
            b = y - 1;
        }
        long long sol = 0;
        std::sort(ans.begin(), ans.end());

        for (int i = 1; i < (int)ans.size(); i++)
            sol = std::max(sol, ans[i] - ans[i - 1]);
        return sol;
    }
    long long e, r;
    MinMax(0, R, &e, &r);
    r -= e;
    long long dist = (r + N - 2) / (N - 1), st = e, ans = 0, val = -1;
    for (int i = 1; i < N; i++) {
        long long a, b;
        MinMax(st, st + dist, &a, &b);
        st += dist + 1;

        if (a != -1) {
            if (val != -1)
                ans = std::max(ans, a - val);
            val = b;
        }
    }

    if (N == 2)
        ans = r;

    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 356 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 15 ms 896 KB Output is correct
17 Correct 21 ms 888 KB Output is correct
18 Correct 16 ms 896 KB Output is correct
19 Correct 17 ms 904 KB Output is correct
20 Correct 12 ms 896 KB Output is correct
21 Correct 60 ms 2288 KB Output is correct
22 Correct 60 ms 2288 KB Output is correct
23 Correct 63 ms 2288 KB Output is correct
24 Correct 58 ms 2292 KB Output is correct
25 Correct 49 ms 2288 KB Output is correct
26 Correct 57 ms 2288 KB Output is correct
27 Correct 57 ms 2288 KB Output is correct
28 Correct 55 ms 2288 KB Output is correct
29 Correct 58 ms 2296 KB Output is correct
30 Correct 43 ms 2256 KB Output is correct
31 Correct 2 ms 256 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 3 ms 332 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 256 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 3 ms 256 KB Output is correct
15 Correct 3 ms 256 KB Output is correct
16 Correct 22 ms 512 KB Output is correct
17 Correct 18 ms 512 KB Output is correct
18 Correct 19 ms 512 KB Output is correct
19 Correct 19 ms 512 KB Output is correct
20 Correct 9 ms 512 KB Output is correct
21 Correct 66 ms 1024 KB Output is correct
22 Correct 65 ms 1024 KB Output is correct
23 Correct 67 ms 1144 KB Output is correct
24 Correct 68 ms 1144 KB Output is correct
25 Correct 63 ms 1152 KB Output is correct
26 Correct 80 ms 1144 KB Output is correct
27 Correct 69 ms 1144 KB Output is correct
28 Correct 67 ms 1116 KB Output is correct
29 Correct 76 ms 1176 KB Output is correct
30 Correct 41 ms 1272 KB Output is correct
31 Correct 2 ms 256 KB Output is correct
32 Correct 2 ms 256 KB Output is correct