Submission #238815

# Submission time Handle Problem Language Result Execution time Memory
238815 2020-06-13T02:51:52 Z balbit Gap (APIO16_gap) C++14
100 / 100
76 ms 2344 KB
#include <bits/stdc++.h>
#ifndef BALBIT
#include "gap.h"
#endif // BALBIT
using namespace std;

#define ll long long
#define pii pair<int, int>
#define f first
#define s second


#define SZ(x) (int)(x.size())
#define ALL(x) (x).begin(), (x).end()
#define pb push_back

#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<" "<<#__VA_ARGS__<<": ", _do(__VA_ARGS__)
template<typename T> void _do(T && x) {cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T && x, S&&...y) {cerr<<x<<", "; _do(y...);}
#define IOS()
#else
#define IOS() ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define bug(...)
#endif // BALBIT

const int maxn = 1e6+5;

#ifdef BALBIT
void MinMax(ll l,ll r,ll *s, ll *t) {
    bug(l,r); cin>>*s>>*t;
}
#endif // BALBIT

ll findGap(int T, int n) {
    if (T == 2){
        ll s, t;
        MinMax(0, 1e18, &s, &t);
        ll gp = (t-s+n-1-1) / (n-1);
        bug(gp);
        ll prev = s;
        ll re = 0;
        for (ll i = s+1; i < t; i += gp) {
            ll a, b;
            MinMax(i,min(i+gp-1,t),&a,&b);
            if (a == -1) continue;
            re = max(re, a-prev);
            prev = b;
        }
        return re;
    }
    else{
        vector<ll> hv;
        ll L = 0, R= 1e18;
        ll s=1, t=1;
        for (int i = 0; i<(n+1)/2; ++i){
            MinMax(L,R,&s,&t);
            hv.pb(s); hv.pb(t);
            L = s+1; R = t-1;
        }
        sort(ALL(hv));
        ll re = 0;
        for (int i = 1; i<SZ(hv); ++i) {
            re = max(re, hv[i] - hv[i-1]);
        }
        return re;
    }
}
#ifdef BALBIT
signed main(){
    IOS();
    cout<<findGap(1,4)<<endl;
}
#endif
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 6 ms 384 KB Output is correct
16 Correct 17 ms 896 KB Output is correct
17 Correct 17 ms 896 KB Output is correct
18 Correct 17 ms 1100 KB Output is correct
19 Correct 19 ms 864 KB Output is correct
20 Correct 13 ms 896 KB Output is correct
21 Correct 74 ms 2288 KB Output is correct
22 Correct 57 ms 2288 KB Output is correct
23 Correct 57 ms 2288 KB Output is correct
24 Correct 59 ms 2288 KB Output is correct
25 Correct 49 ms 2292 KB Output is correct
26 Correct 63 ms 2288 KB Output is correct
27 Correct 58 ms 2344 KB Output is correct
28 Correct 58 ms 2264 KB Output is correct
29 Correct 56 ms 2276 KB Output is correct
30 Correct 42 ms 2296 KB Output is correct
31 Correct 4 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 6 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 23 ms 512 KB Output is correct
17 Correct 20 ms 512 KB Output is correct
18 Correct 19 ms 512 KB Output is correct
19 Correct 19 ms 512 KB Output is correct
20 Correct 11 ms 512 KB Output is correct
21 Correct 76 ms 1144 KB Output is correct
22 Correct 69 ms 1136 KB Output is correct
23 Correct 69 ms 1144 KB Output is correct
24 Correct 66 ms 1148 KB Output is correct
25 Correct 60 ms 1144 KB Output is correct
26 Correct 72 ms 1172 KB Output is correct
27 Correct 69 ms 1272 KB Output is correct
28 Correct 70 ms 1144 KB Output is correct
29 Correct 75 ms 1144 KB Output is correct
30 Correct 37 ms 1152 KB Output is correct
31 Correct 4 ms 384 KB Output is correct
32 Correct 4 ms 384 KB Output is correct