Submission #861193

# Submission time Handle Problem Language Result Execution time Memory
861193 2023-10-15T15:45:40 Z Dec0Dedd Gap (APIO16_gap) C++14
89.0375 / 100
46 ms 3876 KB
#include <bits/stdc++.h>
#include "gap.h"

using namespace std;

typedef long long ll;

const ll INF = 1e18;

ll solve1(int n) {
    ll a[n]={};

    ll lf=-1, rf=INF+1, lp=0, rp=n-1;
    while (lp <= rp) {
        ll mn, mx; MinMax(lf+1, rf-1, &mn, &mx);
        if (mn == -1) break;
        a[lp++]=mn, a[rp--]=mx;
        lf=mn, rf=mx;
    }

    ll ans=1;
    for (int i=0; i<n-1; ++i) ans=max(ans, a[i+1]-a[i]);
    return ans;
}

ll solve2(int n) {
    ll lf, rf; MinMax(0, INF, &lf, &rf);
    if (n == 2) return rf-lf;

    ll ans=(rf-lf)/n, d=(rf-lf)/(n-1), lst=lf;
    while (lf < rf) {
        ll mn, mx; MinMax(lf+1, lf+d, &mn, &mx);
        if (mn != -1) ans=max(ans, mn-lst), lst=mx;
        lf+=d;
    } return ans;
}

ll findGap(int t, int n) {
    if (t == 1) return solve1(n);
    return solve2(n);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 2644 KB Output is correct
3 Correct 0 ms 2392 KB Output is correct
4 Correct 0 ms 2392 KB Output is correct
5 Correct 0 ms 2392 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 8 ms 2724 KB Output is correct
17 Correct 8 ms 2724 KB Output is correct
18 Correct 8 ms 2588 KB Output is correct
19 Correct 8 ms 2580 KB Output is correct
20 Correct 6 ms 2572 KB Output is correct
21 Correct 30 ms 3616 KB Output is correct
22 Correct 30 ms 3624 KB Output is correct
23 Correct 30 ms 3620 KB Output is correct
24 Correct 30 ms 3620 KB Output is correct
25 Correct 29 ms 3876 KB Output is correct
26 Correct 30 ms 3608 KB Output is correct
27 Correct 30 ms 3616 KB Output is correct
28 Correct 33 ms 3620 KB Output is correct
29 Correct 30 ms 3640 KB Output is correct
30 Correct 25 ms 3632 KB Output is correct
31 Correct 1 ms 2392 KB Output is correct
32 Correct 0 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 0 ms 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2388 KB Output is correct
6 Correct 0 ms 2392 KB Output is correct
7 Correct 0 ms 2392 KB Output is correct
8 Correct 0 ms 2392 KB Output is correct
9 Correct 0 ms 2392 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 10 ms 2752 KB Output is correct
17 Correct 10 ms 2588 KB Output is correct
18 Correct 10 ms 3000 KB Output is correct
19 Correct 11 ms 2592 KB Output is correct
20 Partially correct 6 ms 2572 KB Partially correct
21 Correct 42 ms 3064 KB Output is correct
22 Correct 41 ms 2856 KB Output is correct
23 Correct 41 ms 2864 KB Output is correct
24 Correct 41 ms 2860 KB Output is correct
25 Correct 39 ms 2848 KB Output is correct
26 Correct 41 ms 2856 KB Output is correct
27 Correct 41 ms 3092 KB Output is correct
28 Correct 41 ms 2832 KB Output is correct
29 Correct 46 ms 2836 KB Output is correct
30 Partially correct 25 ms 2856 KB Partially correct
31 Correct 1 ms 2392 KB Output is correct
32 Correct 0 ms 2392 KB Output is correct