Submission #721957

# Submission time Handle Problem Language Result Execution time Memory
721957 2023-04-11T09:15:25 Z Magikarp4000 Gap (APIO16_gap) C++17
100 / 100
70 ms 1940 KB
#include "gap.h"
#include <bits/stdc++.h>
using namespace std;
#define INF int(1e9+7)
#define FOR(i,s,n) for (int i = s; i < n; i++)
#define FORR(i,n,s) for (int i = n; i > s; i--)
#define FORX(u, arr) for (auto u : arr)
#define ln '\n'
#define ll long long
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define ALL(v) v.begin(), v.end()
#define PB push_back
#define F first
#define S second
const ll LLINF = 1e18+1;
#define int long long

int findGap(int32_t sub, int32_t n) {
    if (sub == 1) {
        int l = -1, r = 2e18;
        vector<int> a(n,-1);
        FOR(i,0,(n+1)/2) {
            MinMax(l+1,r-1,&l,&r);
            a[i] = l;
            a[n-i-1] = r;
        }
        int res = 0;
        FOR(i,0,n-1) res = max(res, a[i+1]-a[i]);
        return res;
    }
    else {
        int mi = 0, ma = 1e18;
        MinMax(mi,ma,&mi,&ma);
        if (n == 2) return ma-mi;
        int d = ma-mi;
        int block = d%(n-1) == 0 ? d/(n-1) : d/(n-1)+1;
        int l = mi, x, y, old = mi, cnt = 0;
        int res = 0;
        while (cnt < n-1) {
            MinMax(l,l+block,&x,&y);
            if (x != -1) {
                res = max(res, x-old);
                old = y;
            }
            cnt++;
            l += block+1;
        }
        return res;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 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 0 ms 208 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 1 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 12 ms 720 KB Output is correct
17 Correct 10 ms 688 KB Output is correct
18 Correct 10 ms 680 KB Output is correct
19 Correct 10 ms 704 KB Output is correct
20 Correct 7 ms 672 KB Output is correct
21 Correct 37 ms 1864 KB Output is correct
22 Correct 42 ms 1940 KB Output is correct
23 Correct 41 ms 1868 KB Output is correct
24 Correct 36 ms 1832 KB Output is correct
25 Correct 33 ms 1832 KB Output is correct
26 Correct 41 ms 1864 KB Output is correct
27 Correct 39 ms 1780 KB Output is correct
28 Correct 44 ms 1864 KB Output is correct
29 Correct 43 ms 1784 KB Output is correct
30 Correct 32 ms 1824 KB Output is correct
31 Correct 1 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 1 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 1 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 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 12 ms 464 KB Output is correct
17 Correct 12 ms 508 KB Output is correct
18 Correct 13 ms 512 KB Output is correct
19 Correct 13 ms 464 KB Output is correct
20 Correct 7 ms 516 KB Output is correct
21 Correct 50 ms 1080 KB Output is correct
22 Correct 62 ms 1080 KB Output is correct
23 Correct 51 ms 1048 KB Output is correct
24 Correct 55 ms 968 KB Output is correct
25 Correct 52 ms 1060 KB Output is correct
26 Correct 70 ms 968 KB Output is correct
27 Correct 54 ms 1060 KB Output is correct
28 Correct 50 ms 1056 KB Output is correct
29 Correct 50 ms 1076 KB Output is correct
30 Correct 27 ms 988 KB Output is correct
31 Correct 0 ms 208 KB Output is correct
32 Correct 0 ms 208 KB Output is correct