Submission #813115

# Submission time Handle Problem Language Result Execution time Memory
813115 2023-08-07T13:40:02 Z Pikachu Gap (APIO16_gap) C++17
100 / 100
46 ms 1864 KB
#include <bits/stdc++.h>
#define int long long

using namespace std;

template<typename T>
inline bool maxi(T &x, const T &val)
{
    if (x < val) return x = val, true;
    return false;
}

template<typename T>
inline bool mini(T &x, const T &val)
{
    if (x > val) return x = val, true;
    return false;
}

const int maxn = 3e5 + 10, oo = 1e18;
int n;
int a[maxn];
int res;

void MinMax(long long s, long long t, long long *mn, long long *mx);

int solve1()
{
    int st = 0, en = oo;
    int *tmpn = new int(0), *tmpx = new int(oo);
    int curst = 1, curen = n;
    while (curst <= curen) {
        MinMax(st, en, tmpn, tmpx);
        a[curst++] = *tmpn;
        st = *tmpn + 1;
        a[curen--] = *tmpx;
        en = *tmpx - 1;
    }
    for (int i = 1; i < n; i++) {
        maxi(res, a[i + 1] - a[i]);
    }
    return res;
}

int *tmpn = new int(0), *tmpx = new int(0);
int cnt = 0;

int solve2()
{
    MinMax(0, oo, tmpn, tmpx);
    a[++cnt] = *tmpn;
    a[++cnt] = *tmpx;
    int step = (*tmpx - *tmpn + n) / (n - 1);
    for (int i = 1, cur = *tmpn; i < n; i++) {
        // cout << i << endl;
        MinMax(cur + 1, cur + step, tmpn, tmpx);
        cur += step;
        if (*tmpn == -1) continue;
        a[++cnt] = *tmpn;
        if (*tmpn != *tmpx) a[++cnt] = *tmpx;
    }
    sort(a + 1, a + cnt + 1);
    for (int i = 1; i < cnt; i++) {
        maxi(res, a[i + 1] - a[i]);
    }
    return res;
}

int findGap(signed sub, signed n)
{
    ::n = n;
    if (sub == 1) return solve1();
    else return solve2();
}

#undef int
# 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 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 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 7 ms 720 KB Output is correct
17 Correct 7 ms 680 KB Output is correct
18 Correct 9 ms 720 KB Output is correct
19 Correct 7 ms 720 KB Output is correct
20 Correct 6 ms 592 KB Output is correct
21 Correct 34 ms 1804 KB Output is correct
22 Correct 27 ms 1832 KB Output is correct
23 Correct 27 ms 1752 KB Output is correct
24 Correct 27 ms 1772 KB Output is correct
25 Correct 25 ms 1812 KB Output is correct
26 Correct 28 ms 1820 KB Output is correct
27 Correct 28 ms 1788 KB Output is correct
28 Correct 34 ms 1864 KB Output is correct
29 Correct 27 ms 1864 KB Output is correct
30 Correct 23 ms 1848 KB Output is correct
31 Correct 0 ms 208 KB Output is correct
32 Correct 0 ms 208 KB Output is correct
# 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 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 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 620 KB Output is correct
17 Correct 10 ms 648 KB Output is correct
18 Correct 10 ms 692 KB Output is correct
19 Correct 10 ms 688 KB Output is correct
20 Correct 5 ms 464 KB Output is correct
21 Correct 41 ms 1708 KB Output is correct
22 Correct 41 ms 1764 KB Output is correct
23 Correct 46 ms 1760 KB Output is correct
24 Correct 42 ms 1664 KB Output is correct
25 Correct 45 ms 1864 KB Output is correct
26 Correct 40 ms 1696 KB Output is correct
27 Correct 45 ms 1664 KB Output is correct
28 Correct 41 ms 1736 KB Output is correct
29 Correct 40 ms 1700 KB Output is correct
30 Correct 22 ms 1160 KB Output is correct
31 Correct 0 ms 208 KB Output is correct
32 Correct 0 ms 208 KB Output is correct