Submission #929450

# Submission time Handle Problem Language Result Execution time Memory
929450 2024-02-18T05:40:30 Z Foolestboy Gap (APIO16_gap) C++14
42.8863 / 100
48 ms 3136 KB
#ifndef GNORT
#include "gap.h"
#endif // GNORT
#include <bits/stdc++.h>

#define SQR(x)    (1LL * ((x) * (x)))
#define MASK(i)   (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
#define fi        first
#define se        second
#define pb        push_back
#define all(x)    x.begin(), x.end()
#define rall(x)   x.rbegin(), x.rend()
#define sz(s)     (int)s.size()
#define prev      __prev
#define next      __next
#define left      __left
#define right     __right

#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned int ui;

using namespace std;

const int mod = 1e9 + 7;
const int INF = 1e9 + 7;
const ll INFLL = (ll)2e18 + 7LL;
const ld PI = acos(-1);

const int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
const int dy[] = {0, 0, 1, -1, -1, -1, 1, 1};

template<class BUI, class TRONG>
    bool minimize(BUI &x, const TRONG y){
        if(x > y){
            x = y;
            return true;
        } else return false;
    }
template<class BUI, class TRONG>
    bool maximize(BUI &x, const TRONG y){
        if(x < y){
            x = y;
            return true;
        } else return false;
    }

/* Author : Bui Nguyen Duc Trong, Luong Van Chanh High School for the gifted*/
/* Template is copied by Trong */

                           /** Losing in Provincial Contests **/
                                    /** TRYING HARDER**/
                                   /**      ORZ     **/

/* -----------------[ MAIN CODE GOES HERE ]----------------- */

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e5 + 10;

#ifdef GNORT

struct Jury{
    int n, type;
    ll a[N];

    Jury() : n(0) {}

    void init(){
        cin >> type >> n;
        for(int i = 1; i <= n; i++) cin >> a[i];
    }

    void MinMax(ll s, ll t, ll *mn, ll *mx){
        *mn = *mx = -1;
        for(int i = 1; i <= n; i++){
            if(a[i] >= s){
                *mn = a[i];
                break;
            }
        }
        for(int i = n; i >= 1; i--){
            if(a[i] <= t){
                *mx = a[i];
                break;
            }
        }
    }

    void check(ll ans){
        ll res(0);
        for(int i = 1; i < n; i++) maximize(res, a[i + 1] - a[i]);
        if(ans == res) cout << "DUNG" << '\n';
        else{
            cout << "Jury: " << res << '\n';
            cout << "Part: " << ans << '\n';
        }
    }

} jury;

void MinMax(ll s, ll t, ll *mn, ll *mx){
    jury.MinMax(s, t, mn, mx);
}

void check(ll ans){
    jury.check(ans);
}

#endif // GNORT

ll a[N];

ll findGap1(int n){
    MinMax(0, (ll)1e18, &a[1], &a[n]);
    for(int i = 2; i <= n - i + 1; i++){
        MinMax(a[i - 1] + 1, a[n - i + 2] - 1, &a[i], &a[n - i + 1]);
    }
    ll ans = 0;
    for(int i = 1; i < n; i++) maximize(ans, a[i + 1] - a[i]);
    return ans;
}

int n;

void solve(ll l, ll r){
    if(l > r) return;
    ll x, y;
    MinMax(l, r, &x, &y);
    if(x == -1) return;
    a[++n] = x;
    if(x != y){
        a[++n] = y;
        ll mid = (x + y) >> 1;
        solve(x + 1, mid);
        solve(mid + 1, y - 1);
    }
}

ll findGap2(int n){
    solve(0, 1e18);
    sort(a + 1, a + 1 + n);
    ll ans = 0;
    for(int i = 1; i < n; i++) maximize(ans, a[i + 1] - a[i]);
    return ans;
}

ll findGap(int type, int n){
    return type == 1 ? findGap1(n) : findGap2(n);
}
/*
1 4
2 3 6 8
*/

#ifdef GNORT

void solve(){
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    const bool multitest = 0;
    int tt = 1; if(multitest) cin >> tt;

    while( tt-- ){

        jury.init();
        findGap(jury.type, jury.n);

    }

    return 0;
}

#endif
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 0 ms 2392 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2392 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 2404 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 7 ms 2588 KB Output is correct
17 Correct 8 ms 2768 KB Output is correct
18 Correct 9 ms 2776 KB Output is correct
19 Correct 8 ms 2848 KB Output is correct
20 Correct 7 ms 2832 KB Output is correct
21 Correct 29 ms 2872 KB Output is correct
22 Correct 33 ms 2884 KB Output is correct
23 Correct 34 ms 3092 KB Output is correct
24 Correct 28 ms 2876 KB Output is correct
25 Correct 24 ms 2876 KB Output is correct
26 Correct 35 ms 3044 KB Output is correct
27 Correct 31 ms 2924 KB Output is correct
28 Correct 27 ms 2884 KB Output is correct
29 Correct 30 ms 2872 KB Output is correct
30 Correct 24 ms 3064 KB Output is correct
31 Correct 1 ms 2392 KB Output is correct
32 Correct 1 ms 2440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Partially correct 1 ms 2392 KB Partially correct
3 Partially correct 0 ms 2392 KB Partially correct
4 Partially correct 1 ms 2392 KB Partially correct
5 Partially correct 0 ms 2392 KB Partially correct
6 Partially correct 1 ms 2392 KB Partially correct
7 Partially correct 0 ms 2392 KB Partially correct
8 Partially correct 1 ms 2392 KB Partially correct
9 Partially correct 1 ms 2392 KB Partially correct
10 Partially correct 1 ms 2392 KB Partially correct
11 Partially correct 1 ms 2392 KB Partially correct
12 Partially correct 2 ms 2392 KB Partially correct
13 Partially correct 1 ms 2392 KB Partially correct
14 Partially correct 2 ms 2392 KB Partially correct
15 Partially correct 1 ms 2644 KB Partially correct
16 Partially correct 11 ms 2588 KB Partially correct
17 Partially correct 11 ms 2588 KB Partially correct
18 Partially correct 12 ms 2584 KB Partially correct
19 Partially correct 11 ms 2824 KB Partially correct
20 Partially correct 10 ms 2572 KB Partially correct
21 Partially correct 42 ms 3068 KB Partially correct
22 Partially correct 45 ms 2872 KB Partially correct
23 Partially correct 44 ms 2916 KB Partially correct
24 Partially correct 48 ms 3136 KB Partially correct
25 Partially correct 38 ms 2864 KB Partially correct
26 Partially correct 42 ms 3048 KB Partially correct
27 Partially correct 42 ms 2872 KB Partially correct
28 Partially correct 47 ms 3036 KB Partially correct
29 Partially correct 48 ms 3044 KB Partially correct
30 Partially correct 31 ms 2864 KB Partially correct
31 Partially correct 1 ms 2392 KB Partially correct
32 Partially correct 1 ms 2808 KB Partially correct