제출 #1176049

#제출 시각아이디문제언어결과실행 시간메모리
1176049n3rm1nGap (APIO16_gap)C++17
48.54 / 100
75 ms3260 KiB
#include "gap.h"
#include <bits/stdc++.h>
using namespace std;

pair < long long, long long > ask(long long l, long long r)
{
    long long mn, mx;
    MinMax(l, r, &mn, &mx);
    return make_pair(mn, mx);
}
long long findGap(int T, int N)
{

    pair < long long, long long > initial = ask(1LL * 0, 1LL * 1e18);
    long long l = initial.first, r = initial.second;
    long long sz = N, len;
    vector < long long > g;
    g.push_back(l);
    len = r - l + 1;
    long long ans = 0;
    long long range = max(1LL * 1, (len + sz - 1) / (sz));
    long long last = l;
    while(l < r)
    {
        //cout << l << " " << last << endl;
        pair < long long , long long > values = ask(l + 1,  l + 1 + range);
        //cout << l + 1 + range << " checked til " << endl;
        if(values.first != -1)
        {

            sz --;
            ans = max(ans, values.first - last);
            g.push_back(values.first);
            g.push_back(values.second);
            ///cout << "NOTICED "  << values.second << endl;
            l = values.second;
            last = values.second;
        }
        else l = l + 1 + range;
    }
    ///cout << "finished " << endl;
    g.push_back(r);
    long long maxspace = 0;
    /*for (int i = 0; i < g.size()-1; ++ i)
    {
        long long space = g[i+1] - g[i];
        maxspace = max(maxspace, space);
    }*/
    return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...