제출 #1176029

#제출 시각아이디문제언어결과실행 시간메모리
1176029n3rm1nGap (APIO16_gap)C++17
0 / 100
70 ms2240 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;
   /// cout << l << " " << r << endl;
    long long sz = N, len, range;
    vector < long long > g;
    g.push_back(l);
    while(l != r)
    {

       /// cout << l << endl;
        len = r - l + 1;
        range = max(1LL * 1, (len - sz) / (sz-1));
        ///cout << "range is " << range << endl;
        pair < int , int > values = ask(l + 1, min(r, l + range));
        ///cout << l + 1 << " -- " << l + range << endl;
        ///cout << "feedback: " << values.first << " " << values.second << endl;
        if(values.first == -1)l = min(l + range, r);
        else
        {
            sz --;
            g.push_back(values.second);
            ///cout << "NOTICED "  << values.second << endl;
            l = values.second;
        }
    }
    ///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];
        ///cout << space << " " << g[i] << " and " << g[i+1] << endl;
        maxspace = max(maxspace, space);
    }
    return maxspace;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...