제출 #1287558

#제출 시각아이디문제언어결과실행 시간메모리
1287558khoavn2008Gap (APIO16_gap)C++17
0 / 100
21 ms3236 KiB
#ifndef KHOA
#include "gap.h"
#endif // KHOA

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld double
#define FOR(i,l,r) for(int i = (l), _r = (r); i <= _r; i++)
#define FORNG(i,r,l) for(int i = (r), _l = (l); i >= _l; i--)
#define REP(i,r) for(int i = 0, _r = (r); i < _r; i++)
#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define size(v) ((ll)(v).size())
#define MASK(x) (1LL << (x))
#define BIT(x, i) (((x) >> (i)) & 1)

const ll MOD = 1e9 + 7, N = 2e5 + 10, INF = 2e18, LOG = 21;
ll a[N];

#ifdef KHOA
ll A[N] = {-2008, };
void MinMax(ll x,ll y,ll *z,ll *t){
    bool ok = 0;
    FOR(i,1,10){
        if(x <= a[i] && !ok){
            *z = a[i];
            ok = 1;
        }
        if(a[i] <= y)*t = a[i];
    }
}
#endif

ll findGap(int T, int n){
    ll L = 0, R = 1e18;
    ll lo, hi;
    MinMax(L, R, &lo, &hi);
    if(n == 2)return hi - lo;
    L = lo, R = hi;
    ll sz = (R - L + n - 2) / (n - 1);
    ll last = L, ans = -INF;
    for(int l = lo + 1, r = lo + sz, i=1; i<n;i++,l+=sz,r+=sz){
        if(r > R)r = R - 1;
        if(l<=r){
            MinMax(l, r, &lo, &hi);
            if(lo != -1){
                ans = max(ans, lo - last);
                last = hi;
            }
        }else break;
    }
   ans = max(ans, R - last);
    return ans;
}

#ifdef KHOA
int main(){
    FOR(i,1,10)a[i] = i * 10,cerr<<a[i]<<' ';
    cerr<<endl;
    cout<<findGap(1, 10);

}
#endif
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...