답안 #709289

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
709289 2023-03-13T10:21:35 Z lmqzzz Gap (APIO16_gap) C++14
100 / 100
53 ms 2876 KB
#include "gap.h"

#include <bits/stdc++.h>
using namespace std;
#define int64_t long long

long long findGap(int T, int N) {
        if (T == 1) {
                vector<int64_t> l, r;
                int times = N + 1 >> 1;
                int64_t ll = 0, rr = 1e18;
                while (times--) {
                        int64_t a, b;
                        MinMax(ll, rr, &a, &b);
                        l.emplace_back(a);
                        r.emplace_back(b);
                        ll = a + 1, rr = b - 1;
                }
                if (l.back() == r.back()) l.pop_back();
                reverse(r.begin(), r.end());
                l.insert(l.end(), r.begin(), r.end());
                int64_t res = 0;
                for (int i = 1; i < N; i++) res = max(res, l[i] - l[i - 1]);
                return res;
        } else {
                int64_t res = 0;
                int64_t LIMIT_LEFT, LIMIT_RIGHT;
                MinMax(0, 1e18, &LIMIT_LEFT, &LIMIT_RIGHT);
                if (N == 2) return LIMIT_RIGHT - LIMIT_LEFT;
                LIMIT_LEFT++;
                LIMIT_RIGHT--;
                N -= 2;
                const int64_t BLOCK_SIZE = (LIMIT_RIGHT - LIMIT_LEFT + N) / (N + 1);
                int64_t cur_l = LIMIT_LEFT;
                int64_t last = LIMIT_LEFT - 1;
                while (cur_l <= LIMIT_RIGHT) {
                        int64_t l = cur_l;
                        int64_t r = cur_l + BLOCK_SIZE - 1;
                        r = min<int64_t>(r, LIMIT_RIGHT);
                        cur_l = r + 1;
                        int64_t a, b;
                        MinMax(l, r, &a, &b);
                        if (a == -1) continue;
                        if (last != -1) res = max(res, a - last);
                        last = b;
                }
                res = max(res, LIMIT_RIGHT + 1 - last);
                return res;
        }
        return 0;
}

Compilation message

gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:10:31: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   10 |                 int times = N + 1 >> 1;
      |                             ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 9 ms 940 KB Output is correct
17 Correct 9 ms 976 KB Output is correct
18 Correct 9 ms 948 KB Output is correct
19 Correct 10 ms 976 KB Output is correct
20 Correct 7 ms 976 KB Output is correct
21 Correct 40 ms 2692 KB Output is correct
22 Correct 34 ms 2760 KB Output is correct
23 Correct 44 ms 2876 KB Output is correct
24 Correct 38 ms 2744 KB Output is correct
25 Correct 31 ms 2752 KB Output is correct
26 Correct 37 ms 2760 KB Output is correct
27 Correct 35 ms 2780 KB Output is correct
28 Correct 41 ms 2756 KB Output is correct
29 Correct 38 ms 2672 KB Output is correct
30 Correct 32 ms 2796 KB Output is correct
31 Correct 0 ms 208 KB Output is correct
32 Correct 1 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 0 ms 252 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 13 ms 464 KB Output is correct
17 Correct 14 ms 464 KB Output is correct
18 Correct 11 ms 464 KB Output is correct
19 Correct 12 ms 464 KB Output is correct
20 Correct 7 ms 432 KB Output is correct
21 Correct 50 ms 1056 KB Output is correct
22 Correct 48 ms 1056 KB Output is correct
23 Correct 53 ms 1060 KB Output is correct
24 Correct 50 ms 1160 KB Output is correct
25 Correct 47 ms 968 KB Output is correct
26 Correct 53 ms 1160 KB Output is correct
27 Correct 49 ms 1084 KB Output is correct
28 Correct 53 ms 1088 KB Output is correct
29 Correct 49 ms 1060 KB Output is correct
30 Correct 27 ms 968 KB Output is correct
31 Correct 0 ms 208 KB Output is correct
32 Correct 0 ms 208 KB Output is correct