Submission #479585

# Submission time Handle Problem Language Result Execution time Memory
479585 2021-10-12T09:03:00 Z Habitus Gap (APIO16_gap) C++14
100 / 100
74 ms 4048 KB
#include "gap.h"
#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define dec(x, y) fixed << setprecision((y)) << (x)
#define xx first
#define yy second
#define srt(v) sort((v).begin(), (v).end())
#define srtr(v) sort((v).rbegin(), (v).rend())
#define pb push_back
#define popb pop_back
#define sz(a) (int)(a).size()
#define len(a) (int)(a).length()
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll maks=(ll)1e18;
/*ll b[100002];
int m;
void MinMax(ll s, ll t, ll &mn, ll &mx) {
    int it=lower_bound(b, b+m, s)-b;
    int it1=lower_bound(b, b+m, t+1)-1-b;
    if(it1<it) {mn=mx=-1;}
    else {mn=b[it]; mx=b[it1];}
}*/
ll findGap(int T, int N) {
    int n=N;
    if(T==1) {
        ll a[100002];
        ll mini=0LL, maxi=maks+1LL;
        for(int i=0; i<(n+1)/2; ++i) {
            MinMax(mini+1, maxi-1, &mini, &maxi);
            a[i]=mini;
            a[n-i-1]=maxi;
        }
        maxi=0LL;
        for(int i=1; i<n; ++i) {
            maxi=max(maxi, a[i]-a[i-1]);
        }
        return maxi;
    }
    ll mini, maxi;
    MinMax(1LL, maks, &mini, &maxi);
    vector<ll> v;
    v.pb(mini); v.pb(maxi);
    ll x=ceil((double)(maxi-mini+1LL)/(double)((ll)n-1LL));
    ll mn1, mx1;
    for(int i=0;; ++i) {
        if(mini+(ll)i*x>=maxi) break;
        MinMax((i==0?1LL:0LL)+mini+(ll)i*x, min(mini+(ll)(i+1)*x-1LL, maxi-1LL), &mn1, &mx1);
        if(mn1!=-1) {v.pb(mn1); v.pb(mx1);}
    }
    srt(v);
    maxi=0LL;
    for(int i=1; i<sz(v); ++i) {
        maxi=max(maxi, v[i]-v[i-1]);
    }
    return maxi;
}
/*int main() {
    cin >> m;
    for(int i=0; i<m; ++i) {
        cin >> b[i];
    }
    cout << findGap(2, m);
    return 0;
}*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 968 KB Output is correct
2 Correct 1 ms 1096 KB Output is correct
3 Correct 1 ms 968 KB Output is correct
4 Correct 1 ms 968 KB Output is correct
5 Correct 1 ms 968 KB Output is correct
6 Correct 1 ms 968 KB Output is correct
7 Correct 1 ms 1096 KB Output is correct
8 Correct 1 ms 968 KB Output is correct
9 Correct 1 ms 968 KB Output is correct
10 Correct 1 ms 968 KB Output is correct
11 Correct 1 ms 1096 KB Output is correct
12 Correct 1 ms 1096 KB Output is correct
13 Correct 1 ms 1096 KB Output is correct
14 Correct 1 ms 1096 KB Output is correct
15 Correct 1 ms 1096 KB Output is correct
16 Correct 11 ms 1212 KB Output is correct
17 Correct 11 ms 1300 KB Output is correct
18 Correct 11 ms 1284 KB Output is correct
19 Correct 11 ms 1224 KB Output is correct
20 Correct 9 ms 1224 KB Output is correct
21 Correct 45 ms 1728 KB Output is correct
22 Correct 42 ms 1820 KB Output is correct
23 Correct 47 ms 1768 KB Output is correct
24 Correct 42 ms 1852 KB Output is correct
25 Correct 44 ms 1820 KB Output is correct
26 Correct 45 ms 1820 KB Output is correct
27 Correct 61 ms 1816 KB Output is correct
28 Correct 43 ms 1820 KB Output is correct
29 Correct 43 ms 1784 KB Output is correct
30 Correct 41 ms 1736 KB Output is correct
31 Correct 1 ms 968 KB Output is correct
32 Correct 1 ms 968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 968 KB Output is correct
2 Correct 1 ms 968 KB Output is correct
3 Correct 1 ms 968 KB Output is correct
4 Correct 1 ms 968 KB Output is correct
5 Correct 1 ms 968 KB Output is correct
6 Correct 1 ms 968 KB Output is correct
7 Correct 1 ms 968 KB Output is correct
8 Correct 1 ms 968 KB Output is correct
9 Correct 2 ms 1096 KB Output is correct
10 Correct 1 ms 968 KB Output is correct
11 Correct 2 ms 1096 KB Output is correct
12 Correct 2 ms 1096 KB Output is correct
13 Correct 4 ms 1096 KB Output is correct
14 Correct 2 ms 1096 KB Output is correct
15 Correct 1 ms 1096 KB Output is correct
16 Correct 15 ms 1608 KB Output is correct
17 Correct 15 ms 1628 KB Output is correct
18 Correct 15 ms 1608 KB Output is correct
19 Correct 16 ms 1616 KB Output is correct
20 Correct 9 ms 1284 KB Output is correct
21 Correct 61 ms 2936 KB Output is correct
22 Correct 64 ms 2952 KB Output is correct
23 Correct 64 ms 3000 KB Output is correct
24 Correct 71 ms 2928 KB Output is correct
25 Correct 66 ms 4048 KB Output is correct
26 Correct 71 ms 3000 KB Output is correct
27 Correct 74 ms 2916 KB Output is correct
28 Correct 70 ms 3012 KB Output is correct
29 Correct 69 ms 2960 KB Output is correct
30 Correct 33 ms 2172 KB Output is correct
31 Correct 1 ms 968 KB Output is correct
32 Correct 1 ms 968 KB Output is correct