This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "gap.h"
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef long double ld;
typedef pair<ll, int> ii;
const int mod = (int) 1e9 + 7;
const ll inf = 1LL << 60;
const int maxn = (int) 1e5 + 5;
const ld eps = 1e-9;
vector<ll> a, b;
ll l[maxn], r[maxn];
ll subtask1(int N) {
ll L = 0, R = inf;
int pl = 0, pr = N - 1;
a.resize(N);
while (pl <= pr) {
MinMax(L, R, &a[pl], &a[pr]);
L = a[pl] + 1;
R = a[pr] - 1;
pl ++;
pr --;
}
ll res = 1;
rep(i, 1, N) res = max(res, a[i] - a[i - 1]);
return res;
}
ll subtask2(int N) {
a.assign(N + 1, 0);
b.assign(N + 1, 0);
MinMax(0, inf, &a[0], &a[N]);
b[0] = a[0]; b[N] = a[N];
ll len = a[N] - a[0] - 1;
ll g = min(len, 1LL * N - 1);
ll sg = len % g;
ll bg = g - sg;
l[0] = r[0] = a[0];
a[g + 1] = a[N];
b[g + 1] = b[N];
rep(i, 1, g + 1) {
l[i] = r[i - 1] + 1;
if(i <= sg) r[i] = l[i] + (len / g) - 1;
else r[i] = l[i] + (len / g);
MinMax(l[i], r[i], &a[i], &b[i]);
}
ll res = 1;
int j = 0;
rep(i, 0, g + 2) {
res = max(res, a[i] - b[j]);
if(a[i] == -1 && b[i] == -1) continue;
j = i;
}
return res;
}
ll findGap(int T, int N) {
if(T == 1) return subtask1(N);
if(T == 2) return subtask2(N);
}
Compilation message (stderr)
gap.cpp: In function 'll subtask2(int)':
gap.cpp:46:8: warning: unused variable 'bg' [-Wunused-variable]
ll bg = g - sg;
^
gap.cpp: In function 'll findGap(int, int)':
gap.cpp:69:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |