답안 #551786

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
551786 2022-04-21T14:21:50 Z hoanghq2004 Gap (APIO16_gap) C++14
100 / 100
63 ms 2372 KB
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include "gap.h"

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

mt19937 gen(std :: chrono :: system_clock :: now().time_since_epoch().count());

long long a[1000010];

long long findGap(int T, int n) {
    if (T == 1) {
        long long L = 0, R = 1e18;
        int lhs = 1, rhs = n;
        while (lhs <= rhs) {
            long long temp1 = 0, temp2 = 0;
            long long *nL = &temp1, *nR = &temp2;
            MinMax(L, R, nL, nR);
            L = *nL, R = *nR;
            a[lhs] = L, a[rhs] = R;
            ++L, --R;
            ++lhs, --rhs;
        }
        long long ans = 0;
        for (int i = 1; i < n; ++i) ans = max(ans, a[i + 1] - a[i]);
        return ans;
    } else {
        long long L = 0, R = 1e18, x, y;
        MinMax(L, R, &x, &y);
        L = x, R = y;
        vector <long long> a = {L};
        long long gap = (R - L) / (n - 1);
        for (++L; L < R && a.size() <= n; L += gap + 1) {
            long long x, y;
            MinMax(L, L + gap, &x, &y);
            if (x != -1 && y != -1) {
                a.push_back(x);
                if (x != y) a.push_back(y);
            }
        }
        a.push_back(R);
        long long ans = 0;
        for (int i = 1; i < a.size(); ++i) ans = max(ans, a[i] - a[i - 1]);
        return ans;
    }
}

Compilation message

gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:40:37: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   40 |         for (++L; L < R && a.size() <= n; L += gap + 1) {
      |                            ~~~~~~~~~^~~~
gap.cpp:50:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         for (int i = 1; i < a.size(); ++i) ans = max(ans, a[i] - a[i - 1]);
      |                         ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 1 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 336 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 0 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 11 ms 604 KB Output is correct
17 Correct 11 ms 724 KB Output is correct
18 Correct 9 ms 688 KB Output is correct
19 Correct 9 ms 720 KB Output is correct
20 Correct 9 ms 720 KB Output is correct
21 Correct 38 ms 1840 KB Output is correct
22 Correct 39 ms 1848 KB Output is correct
23 Correct 46 ms 1796 KB Output is correct
24 Correct 36 ms 1840 KB Output is correct
25 Correct 30 ms 1840 KB Output is correct
26 Correct 36 ms 1856 KB Output is correct
27 Correct 45 ms 1828 KB Output is correct
28 Correct 39 ms 1792 KB Output is correct
29 Correct 34 ms 1764 KB Output is correct
30 Correct 30 ms 1768 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 336 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 0 ms 336 KB Output is correct
9 Correct 0 ms 336 KB Output is correct
10 Correct 0 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 15 ms 820 KB Output is correct
17 Correct 16 ms 904 KB Output is correct
18 Correct 16 ms 824 KB Output is correct
19 Correct 14 ms 888 KB Output is correct
20 Correct 7 ms 532 KB Output is correct
21 Correct 63 ms 2256 KB Output is correct
22 Correct 51 ms 2220 KB Output is correct
23 Correct 53 ms 2256 KB Output is correct
24 Correct 57 ms 2372 KB Output is correct
25 Correct 57 ms 2212 KB Output is correct
26 Correct 52 ms 2184 KB Output is correct
27 Correct 60 ms 2192 KB Output is correct
28 Correct 61 ms 2172 KB Output is correct
29 Correct 58 ms 2216 KB Output is correct
30 Correct 29 ms 1460 KB Output is correct
31 Correct 0 ms 208 KB Output is correct
32 Correct 0 ms 208 KB Output is correct