답안 #976464

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
976464 2024-05-06T15:08:51 Z biank Gap (APIO16_gap) C++14
100 / 100
45 ms 3856 KB
#include <bits/stdc++.h>
#include "gap.h"

using namespace std;

using ll = long long;

#define all(x) begin(x), end(x)

const ll MAX_A = 1e18;

ll ceilDiv(ll a, ll b) {
    return (a + b - 1) / b;
}

ll findGap(int T, int N) {
    if (T == 1) {
        ll mini = -1LL, maxi = MAX_A + 1LL;
        vector<ll> a(N);
        int l = 0, r = N - 1;
        while (l <= r) {
            MinMax(mini + 1, maxi - 1, &mini, &maxi);
            a[l++] = mini, a[r--] = maxi;
        }
        ll maxGap = 0LL;
        for (int i = 1; i < N; i++) {
            maxGap = max(maxGap, a[i] - a[i - 1]);
        }
        return maxGap;
    } else {
        ll mini = 0LL, maxi = MAX_A;
        MinMax(mini, maxi, &mini, &maxi);
        ll minRes = ceilDiv(maxi - mini + 1LL, N - 1);
        if (N == 2) return maxi - mini;
        ll prevMax = mini, maxGap = 0LL;
        for (ll i = mini; i <= maxi; i += minRes) {
            ll minInRange, maxInRange;
            MinMax(i, i + minRes - 1LL, &minInRange, &maxInRange);
            if (minInRange != -1) {
                maxGap = max(maxGap, minInRange - prevMax);
                prevMax = maxInRange;
            }
        }
        return maxGap;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 2 ms 2392 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2672 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 8 ms 2580 KB Output is correct
17 Correct 8 ms 2588 KB Output is correct
18 Correct 8 ms 2752 KB Output is correct
19 Correct 8 ms 2576 KB Output is correct
20 Correct 7 ms 2568 KB Output is correct
21 Correct 30 ms 3600 KB Output is correct
22 Correct 30 ms 3624 KB Output is correct
23 Correct 30 ms 3624 KB Output is correct
24 Correct 30 ms 3620 KB Output is correct
25 Correct 27 ms 3856 KB Output is correct
26 Correct 32 ms 3624 KB Output is correct
27 Correct 31 ms 3632 KB Output is correct
28 Correct 30 ms 3624 KB Output is correct
29 Correct 30 ms 3628 KB Output is correct
30 Correct 26 ms 3612 KB Output is correct
31 Correct 1 ms 2388 KB Output is correct
32 Correct 1 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2388 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 2 ms 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 0 ms 2392 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 10 ms 2584 KB Output is correct
17 Correct 10 ms 2584 KB Output is correct
18 Correct 13 ms 2588 KB Output is correct
19 Correct 10 ms 2580 KB Output is correct
20 Correct 6 ms 2576 KB Output is correct
21 Correct 44 ms 2840 KB Output is correct
22 Correct 44 ms 2836 KB Output is correct
23 Correct 42 ms 2856 KB Output is correct
24 Correct 43 ms 2980 KB Output is correct
25 Correct 40 ms 2868 KB Output is correct
26 Correct 45 ms 3276 KB Output is correct
27 Correct 40 ms 2856 KB Output is correct
28 Correct 41 ms 2856 KB Output is correct
29 Correct 45 ms 2856 KB Output is correct
30 Correct 24 ms 2852 KB Output is correct
31 Correct 1 ms 2392 KB Output is correct
32 Correct 1 ms 2388 KB Output is correct