Submission #25598

#TimeUsernameProblemLanguageResultExecution timeMemory
25598kajebiiiGap (APIO16_gap)C++14
100 / 100
93 ms6588 KiB
#include "gap.h"

#include <algorithm>
#include <stdio.h>

using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REPO(i,n) for(int (i)=1; (i)<=(int)(n); (i)++)
#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;


const ll MINV = 0, MAXV = 1e18;
const int MAX_N = 1e5 + 100;

ll minV, maxV;

ll Nr[MAX_N][2], Ans[MAX_N];
long long findGap(int T, int N)
{
    if(T == 1) {
        ll ans = 0;
        minV = MINV, maxV = MAXV;        
        int li = 0, ri = N-1;
        for(int i=0; i<(N+1)/2; i++) {
            ll l, r;
            MinMax(minV, maxV, &l, &r);
            Ans[li++] = l;
            Ans[ri--] = r;
            minV = l+1; maxV = r-1;
        }
        for(int i=0; i+1<N; i++)
            ans = max(ans, Ans[i+1] - Ans[i]);
        return ans;
    }
    if(T == 2) {
        MinMax(MINV, MAXV, &minV, &maxV);
        if(N == 2) return maxV - minV;

        ll diff = (maxV-1 - (minV+1) + N-3) / (N-2);
        ll ans = 0, lastR = minV;
        bool isBlank = false;
        for(int i=0; i<N-2; i++) {
            ll l = min(maxV-1, minV+1 + i * diff);
            ll r = min(maxV-1, minV+1 + (i+1) * diff - 1);

            MinMax(l, r, &Nr[i][0], &Nr[i][1]);
//            printf("%lld %lld -> %lld %lld\n", l, r, Nr[i][0], Nr[i][1]);
            if(Nr[i][0] >= 0) {
                if(lastR != -1) ans = max(ans, Nr[i][0] - lastR);
                lastR = Nr[i][1];
            }else{
                isBlank = true;
            }
            if(r == maxV-1) break;
        }
        ans = max(ans, maxV - lastR);
        return ans;
    }
	return 0;
}

Compilation message (stderr)

gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:49:14: warning: variable 'isBlank' set but not used [-Wunused-but-set-variable]
         bool isBlank = false;
              ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...