답안 #48388

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
48388 2018-05-12T13:31:37 Z BThero Gap (APIO16_gap) C++17
100 / 100
75 ms 2940 KB
// Why am I so stupid? :c
#include <bits/stdc++.h>
#include "gap.h"

#define pb push_back
#define mp make_pair

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

#define fi first
#define se second

typedef long long ll;

using namespace std;

long long findGap(int t, int n) {
    ll arr[n * 2 + 5], que[2], ret = 0;
    int sz = 0;

    if (n <= 5 || t == 1) {
        arr[0] = 0, arr[n + 1] = (ll)1e18 + 1;
        int l = 1, r = n;

        while (l <= r) {
            MinMax(arr[l - 1] + 1, arr[r + 1] - 1, arr + l, arr + r);
            ++l, --r;
        }

        for (int i = 1; i < n; ++i) {
            ret = max(ret, arr[i + 1] - arr[i]);
        }
    }
    else {
        MinMax(1, (ll)1e18, que, que + 1);
        ll l = que[0], r = que[1];

        arr[++sz] = l++;
        arr[++sz] = r--;

        ll a = (r - l + 1) / (n - 1);
        ll b = (r - l + 1) % (n - 1);
        ll cur = l;

        for (int i = 1; i < n; ++i) {
            ll len = a;

            if (b > 0) {
                ++len, --b;
            }

            MinMax(cur, cur + len - 1, que, que + 1);

            if (que[0] != -1) {
                arr[++sz] = que[0];
                arr[++sz] = que[1];
            }

            cur += len;
        }

        sort(arr + 1, arr + sz + 1);
        sz = unique(arr + 1, arr + sz + 1) - arr - 1;

        for (int i = 1; i < sz; ++i) {
            ret = max(ret, arr[i + 1] - arr[i]);
        }
    }

    return ret;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 408 KB Output is correct
4 Correct 2 ms 408 KB Output is correct
5 Correct 2 ms 408 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 548 KB Output is correct
8 Correct 2 ms 548 KB Output is correct
9 Correct 2 ms 548 KB Output is correct
10 Correct 2 ms 548 KB Output is correct
11 Correct 3 ms 560 KB Output is correct
12 Correct 3 ms 560 KB Output is correct
13 Correct 3 ms 560 KB Output is correct
14 Correct 2 ms 560 KB Output is correct
15 Correct 2 ms 560 KB Output is correct
16 Correct 15 ms 948 KB Output is correct
17 Correct 15 ms 948 KB Output is correct
18 Correct 15 ms 948 KB Output is correct
19 Correct 15 ms 948 KB Output is correct
20 Correct 11 ms 948 KB Output is correct
21 Correct 57 ms 2096 KB Output is correct
22 Correct 53 ms 2096 KB Output is correct
23 Correct 53 ms 2096 KB Output is correct
24 Correct 66 ms 2096 KB Output is correct
25 Correct 49 ms 2096 KB Output is correct
26 Correct 55 ms 2096 KB Output is correct
27 Correct 56 ms 2096 KB Output is correct
28 Correct 55 ms 2156 KB Output is correct
29 Correct 54 ms 2156 KB Output is correct
30 Correct 41 ms 2160 KB Output is correct
31 Correct 2 ms 2160 KB Output is correct
32 Correct 2 ms 2160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2160 KB Output is correct
2 Correct 2 ms 2160 KB Output is correct
3 Correct 2 ms 2160 KB Output is correct
4 Correct 2 ms 2160 KB Output is correct
5 Correct 2 ms 2160 KB Output is correct
6 Correct 2 ms 2160 KB Output is correct
7 Correct 2 ms 2160 KB Output is correct
8 Correct 2 ms 2160 KB Output is correct
9 Correct 2 ms 2160 KB Output is correct
10 Correct 2 ms 2160 KB Output is correct
11 Correct 3 ms 2160 KB Output is correct
12 Correct 3 ms 2160 KB Output is correct
13 Correct 3 ms 2160 KB Output is correct
14 Correct 3 ms 2160 KB Output is correct
15 Correct 3 ms 2160 KB Output is correct
16 Correct 20 ms 2160 KB Output is correct
17 Correct 22 ms 2160 KB Output is correct
18 Correct 20 ms 2160 KB Output is correct
19 Correct 20 ms 2160 KB Output is correct
20 Correct 9 ms 2160 KB Output is correct
21 Correct 74 ms 2368 KB Output is correct
22 Correct 74 ms 2504 KB Output is correct
23 Correct 74 ms 2504 KB Output is correct
24 Correct 74 ms 2504 KB Output is correct
25 Correct 70 ms 2940 KB Output is correct
26 Correct 75 ms 2940 KB Output is correct
27 Correct 74 ms 2940 KB Output is correct
28 Correct 74 ms 2940 KB Output is correct
29 Correct 75 ms 2940 KB Output is correct
30 Correct 38 ms 2940 KB Output is correct
31 Correct 2 ms 2940 KB Output is correct
32 Correct 2 ms 2940 KB Output is correct