Submission #943890

#TimeUsernameProblemLanguageResultExecution timeMemory
943890Boycl07Gap (APIO16_gap)C++17
100 / 100
45 ms3876 KiB
#include "gap.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define rep(i, n) for(int i = 1; (i) <= (n); ++i)
#define forn(i, l, r) for(int i = (l); i <= (r); ++i)
#define ford(i, r, l) for(int i = (r); i >= (l); --i)
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define FORD(i, n) for(int i = ((n) - 1); i >= 0; --i)
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define endl "\n"
#define task "firework"
#define sz(a) int(a.size())
#define C(x, y) make_pair(x, y)
#define all(a) (a).begin(), (a).end()
#define bit(i, mask) (mask >> i & 1)

template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; }
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; }

inline int readInt()       {char c;while(c=getchar(),c!='-'&&(c<'0'||c>'9'));bool sign=(c=='-');if(sign)c=getchar();int n=c-'0';while(c=getchar(),c>='0'&&c<='9')n=10*n+c-'0';return(!sign)?n:-n;}
inline ll readLong()       {char c;while(c=getchar(),c!='-'&&(c<'0'||c>'9'));bool sign=(c=='-');if(sign)c=getchar();ll  n=c-'0';while(c=getchar(),c>='0'&&c<='9')n=10*n+c-'0';return(!sign)?n:-n;}
inline string readString() {char c;while(c=getchar(),c==' '||c=='\n'||c=='\t');string s({c});while(c=getchar(),c!=EOF&&c!=' '&&c!='\n'&&c!='\t')s+=c;return s;}

static int subtask_num, N;
static long long A[100001];
static long long call_count;

void MinMax(long long, long long, long long*, long long*);

ll findGap(int T, int N)
{
    vector<ll> a(N + 2);
    if(T == 1)
    {
        int l = 1, r = N;
        ll lb = 0, rb = 1e18;
        while(l <= r)
        {
            ll x, y;
            MinMax(lb, rb, &a[l], &a[r]);
            lb = a[l++] + 1;
            rb = a[r--] - 1;
        }
        ll res = 0;
        rep(i, N - 1) maximize(res, a[i + 1] - a[i]);
        return res;
    }
    ll x, y;
    MinMax(0, 1e18, &x, &y);
    a[1] = x, a[N] = y;
    ll res = 0;
    ll Min_step = (a[N] - a[1] - 1) / (N - 1) + 1;
    if(N == 2) return a[N] - a[1];
    for(ll i = a[1], pre = a[1]; i <= a[N]; i += Min_step + 1)
    {
        MinMax(i, i + Min_step, &x, &y);
        if(x != -1) maximize(res, x - pre), pre = y;
    }
    return res;
}

Compilation message (stderr)

gap.cpp: In function 'll findGap(int, int)':
gap.cpp:47:16: warning: unused variable 'x' [-Wunused-variable]
   47 |             ll x, y;
      |                ^
gap.cpp:47:19: warning: unused variable 'y' [-Wunused-variable]
   47 |             ll x, y;
      |                   ^
gap.cpp: At global scope:
gap.cpp:34:18: warning: 'call_count' defined but not used [-Wunused-variable]
   34 | static long long call_count;
      |                  ^~~~~~~~~~
gap.cpp:33:18: warning: 'A' defined but not used [-Wunused-variable]
   33 | static long long A[100001];
      |                  ^
gap.cpp:32:25: warning: 'N' defined but not used [-Wunused-variable]
   32 | static int subtask_num, N;
      |                         ^
gap.cpp:32:12: warning: 'subtask_num' defined but not used [-Wunused-variable]
   32 | static int subtask_num, N;
      |            ^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...