# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
60244 | ainta | Sparklers (JOI17_sparklers) | C++17 | 70 ms | 12384 KiB |
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<cstdio>
#include<algorithm>
#define N_ 101000
using namespace std;
int n, st, n1, n2, D[N_];
long long T, INF = 1e9, X[N_];
long long A[N_], B[N_], AA[N_], BB[N_];
struct point {
int pv;
long long Mn, Mx;
}w[N_];
bool Do() {
int i, cnt = 0;
n1--, n2--;
long long Mx = -4e18, Mn = 4e18;
for (i = 0; i <= n2; i++) {
Mn = min(Mn, B[i]);
if (Mx <= B[i]) {
Mx = B[i];
w[cnt++] = { i,Mn,Mx };
Mn = B[i];
}
}
for (i = 0; i < cnt; i++) {
if (w[i].Mn + A[0] < 0)break;
}
D[0] = i - 1;
if (D[0] == -1)return false;
for (i = 1; i <= n1; i++) {
if (w[D[i - 1]].Mx + A[i] < 0)return false;
int pv = D[i - 1];
while (pv < cnt - 1 && w[pv + 1].Mn + A[i] >= 0)pv++;
D[i] = pv;
}
return w[D[n1]].pv == n2;
}
bool Pos(long long KK) {
long long L = T*KK;
if (L >= 1e9)return true;
int i, j;
for (i = st; i >= 1; i--) {
AA[i] = X[i] + L * 2 * (st - i);
}
for (i = st; i <= n; i++) {
BB[i] = -(X[i] - L * 2 * (i - st));
}
int pv1 = st, pv2 = st;
for (i = st; i >= 1; i--) if (AA[pv1] < AA[i])pv1 = i;
for (i = st; i <= n; i++) if (BB[pv2] < BB[i])pv2 = i;
n1 = 0, n2 = 0;
for (i = st; i >= pv1; i--) A[n1++] = AA[i];
for (i = st; i <= pv2; i++) B[n2++] = BB[i];
if (!Do())return false;
n1 = 0, n2 = 0;
for (i = 1; i <= pv1; i++) A[n1++] = AA[i];
for (i = n; i >= pv2; i--) B[n2++] = BB[i];
if (!Do())return false;
return true;
}
int main() {
int i;
scanf("%d%d%lld", &n, &st, &T);
for (i = 1; i <= n; i++) {
scanf("%lld", &X[i]);
}
long long b = 0, e = 1e9, mid, res;
while (b <= e) {
mid = (b + e) / 2;
if (Pos(mid)) {
res = mid;
e = mid - 1;
}
else b = mid + 1;
}
printf("%d\n", res);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |