답안 #384995

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
384995 2021-04-02T20:50:12 Z thecodingwizard Gap (APIO16_gap) C++11
100 / 100
65 ms 2876 KB
#include <bits/stdc++.h>
#include "gap.h"

using namespace std;

#define f first
#define s second
#define ll long long
#define ii pair<ll, ll>

ii get(ll a, ll b) {
    b = min(b, (ll)1e18);
    ii x;
    MinMax(a, b, &x.f, &x.s);
    return x;
}

long long findGap(int T, int N)
{
    if (T == 1) {
        vector<ll> nums, nums2;
        ii range = make_pair(1, (ll)1e18);
        for (int i = 0; i < (N+1)/2; i++) {
            if (range.f > range.s) break;
            ii res = get(range.f, range.s);
            if (res.f == -1) break;
            nums.push_back(res.f); nums2.push_back(res.s);
            range = make_pair(res.f+1, res.s-1);
        }
        reverse(nums2.begin(), nums2.end());
        for (ll x : nums2) nums.push_back(x);
        ll best = 0;
        for (int i = 0; i < (int)nums.size() - 1; i++) {
            best = max(best, nums[i+1] - nums[i]);
        }
        return best;
    }


    ii boundary = get(1, 1e18);
    ll block = (boundary.s-boundary.f)/(N-1);
    ll prev = boundary.f;

    ll ans = 0;
    for (ll cur = boundary.f + 1; cur < boundary.s; cur += block + 1) {
        ii thing = get(cur, cur+block);
        if (thing.f == -1) continue;
        ans = max(ans, thing.f - prev);
        prev = thing.s;
    }

    ans = max(ans, boundary.s - prev);

    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 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 2 ms 364 KB Output is correct
12 Correct 2 ms 364 KB Output is correct
13 Correct 2 ms 364 KB Output is correct
14 Correct 2 ms 364 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
16 Correct 12 ms 1004 KB Output is correct
17 Correct 11 ms 1004 KB Output is correct
18 Correct 13 ms 1004 KB Output is correct
19 Correct 12 ms 1004 KB Output is correct
20 Correct 9 ms 1004 KB Output is correct
21 Correct 46 ms 2816 KB Output is correct
22 Correct 45 ms 2704 KB Output is correct
23 Correct 45 ms 2704 KB Output is correct
24 Correct 46 ms 2832 KB Output is correct
25 Correct 39 ms 2716 KB Output is correct
26 Correct 46 ms 2704 KB Output is correct
27 Correct 45 ms 2704 KB Output is correct
28 Correct 45 ms 2876 KB Output is correct
29 Correct 45 ms 2704 KB Output is correct
30 Correct 36 ms 2704 KB Output is correct
31 Correct 1 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 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 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 2 ms 364 KB Output is correct
12 Correct 2 ms 364 KB Output is correct
13 Correct 2 ms 364 KB Output is correct
14 Correct 2 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 15 ms 492 KB Output is correct
17 Correct 15 ms 492 KB Output is correct
18 Correct 16 ms 492 KB Output is correct
19 Correct 19 ms 492 KB Output is correct
20 Correct 11 ms 492 KB Output is correct
21 Correct 65 ms 1132 KB Output is correct
22 Correct 60 ms 1132 KB Output is correct
23 Correct 59 ms 1132 KB Output is correct
24 Correct 64 ms 1124 KB Output is correct
25 Correct 55 ms 1132 KB Output is correct
26 Correct 59 ms 1132 KB Output is correct
27 Correct 59 ms 1280 KB Output is correct
28 Correct 62 ms 1132 KB Output is correct
29 Correct 63 ms 1132 KB Output is correct
30 Correct 35 ms 1260 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct