Submission #565502

#TimeUsernameProblemLanguageResultExecution timeMemory
565502Spade1Gap (APIO16_gap)C++14
83.51 / 100
66 ms1992 KiB
#include<bits/stdc++.h>
#include "gap.h"
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ll long long
#define ld long double
#define st first
#define nd second
#define pb push_back
#define INF INT_MAX
using namespace std;

const int NN = 1e5 + 10;


ll a[NN];
int cnt = 0;

ll findGap(int T, int N) {
    if (T == 1) {
        ll mn, mx;
        ll l = 0, r = 1e18;
        for (ll i = 0; i < (N+1)/2; ++i) {
            MinMax(l, r, &mn, &mx);
            a[cnt++] = mn;
            a[cnt++] = mx;
            l = mn+1, r = mx - 1;
        }
        sort(a, a+N);
        ll ans = 0;
        for (int i = 1; i <= N; ++i) ans = max(ans, a[i] - a[i-1]);
        return ans;
    }
    else {
        ll mn, mx;
        MinMax(0, 1e18, &mn, &mx);
        ll step = (mx - mn + N - 2)/(N - 1);
        ll ans = step;
        ll x, y, i, l = mn;
        for (; i + step < mx; i += step+1) {
            MinMax(i, i+step, &x, &y);
            if (x != -1) {
                ans = max(ans, x-l);
                l = y;
            }
        }
        MinMax(i, mx, &x, &y);
        if (x != -1) ans = max(ans, x-l);
        return ans;
    }
}

Compilation message (stderr)

gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:40:18: warning: 'i' may be used uninitialized in this function [-Wmaybe-uninitialized]
   40 |         for (; i + step < mx; i += step+1) {
      |                ~~^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...