Submission #579995

# Submission time Handle Problem Language Result Execution time Memory
579995 2022-06-20T12:39:56 Z stevancv Gap (APIO16_gap) C++14
100 / 100
68 ms 2240 KB
#include <bits/stdc++.h>
#include "gap.h"
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 1e5 + 2;
ll findGap(int t, int n) {
    if (t == 1) {
        vector<ll> a(n);
        ll mn = 0; ll mx = 1e18;
        for (int i = 0; i < n; i++) {
            if (i > n - i - 1) break;
            MinMax(mn, mx, &a[i], &a[n - i - 1]);
            mn = a[i] + 1;
            mx = a[n - i - 1] - 1;
        }
        ll ans = 0;
        for (int i = 1; i < n; i++) smax(ans, a[i] - a[i - 1]);
        return ans;
    }
    vector<ll> a;
    ll mn = 0; ll mx = 1e18;
    MinMax(0, 1e18, &mn, &mx);
    ll gap = (mx - mn + n - 2) / (n - 1);
    a.push_back(mn);
    a.push_back(mx);
    for (ll i = mn + 1; i < mx; i += gap) {
        ll p = 0; ll q = 0;
        MinMax(i, i + gap - 1, &p, &q);
        if (p != -1) a.push_back(p);
        if (q != -1 && p < q) a.push_back(q);
    }
    sort(a.begin(), a.end());
    ll ans = 0;
    for (int i = 1; i < a.size(); i++) smax(ans, a[i] - a[i - 1]);
    return ans;
}

Compilation message

gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:39:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     for (int i = 1; i < a.size(); i++) smax(ans, a[i] - a[i - 1]);
      |                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 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 1 ms 208 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 13 ms 684 KB Output is correct
17 Correct 10 ms 720 KB Output is correct
18 Correct 9 ms 720 KB Output is correct
19 Correct 12 ms 720 KB Output is correct
20 Correct 8 ms 628 KB Output is correct
21 Correct 46 ms 1804 KB Output is correct
22 Correct 38 ms 1864 KB Output is correct
23 Correct 38 ms 1864 KB Output is correct
24 Correct 41 ms 1864 KB Output is correct
25 Correct 44 ms 1828 KB Output is correct
26 Correct 40 ms 1812 KB Output is correct
27 Correct 39 ms 1864 KB Output is correct
28 Correct 37 ms 1828 KB Output is correct
29 Correct 43 ms 1788 KB Output is correct
30 Correct 34 ms 1864 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 1 ms 208 KB Output is correct
# Verdict Execution time Memory 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 1 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 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 15 ms 848 KB Output is correct
17 Correct 15 ms 800 KB Output is correct
18 Correct 14 ms 888 KB Output is correct
19 Correct 14 ms 1016 KB Output is correct
20 Correct 8 ms 520 KB Output is correct
21 Correct 57 ms 2204 KB Output is correct
22 Correct 68 ms 2204 KB Output is correct
23 Correct 64 ms 2188 KB Output is correct
24 Correct 61 ms 2240 KB Output is correct
25 Correct 51 ms 2240 KB Output is correct
26 Correct 59 ms 2216 KB Output is correct
27 Correct 58 ms 2236 KB Output is correct
28 Correct 63 ms 2148 KB Output is correct
29 Correct 53 ms 2136 KB Output is correct
30 Correct 30 ms 1384 KB Output is correct
31 Correct 0 ms 208 KB Output is correct
32 Correct 0 ms 208 KB Output is correct