# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
224516 | Nightlight | Solar Storm (NOI20_solarstorm) | C++14 | 984 ms | 243836 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 <bits/stdc++.h>
#define dist(a, b) (pos[a] - pos[b])
using namespace std;
long long N, K, S;
long long pos[1000005];
long long pre[1000005];
long long sh[1000005];
long long T[1000005][25];
vector<int> loc;
int lift(int u, int f) {
for(int i = 20; i >= 0; i--) {
if(f >= (1 << i)) {
f -= (1 << i);
u = T[u][i];
}
}
return u;
}
int main() {
// freopen("inp", "r", stdin);
scanf("%lld %lld %lld", &N, &S, &K);
for(int i = 2; i <= N; i++) {
scanf("%lld", &pos[i]);
pos[i] += pos[i - 1];
}
for(int i = 1; i <= N; i++) {
scanf("%lld", &pre[i]);
pre[i] += pre[i - 1];
}
//precompute reach dalam O(N)
deque<long long> L, mid;
for(int R = 1; R <= N; R++) {
while(!mid.empty() && dist(R, mid.front()) > K) mid.pop_front();
if(mid.empty()) L.clear();
else {
while(!L.empty() && dist(mid.front(), L.front()) > K) L.pop_front();
}
if(mid.empty()) {
sh[R] = R;
T[R][0] = R - 1;
}else if(L.empty()) {
sh[R] = mid.front();
T[R][0] = mid.front() - 1;
}else {
sh[R] = mid.front();
T[R][0] = L.front() - 1;
}
mid.push_back(R);
L.push_back(R);
}
//precomputebinary lift
for(int j = 1; j <= 20; j++) {
for(int i = 1; i <= N; i++) {
T[i][j] = T[T[i][j - 1]][j - 1];
}
}
//binary lift coba semua kemungkinan
int opt;
long long ans = 0, id, res;
for(int i = S; i <= N; i++) {
opt = lift(i, S);
res = pre[i] - pre[opt];
if(ans < res) {
ans = res;
id = i;
}
}
//bruteforce jawaban
int krg = S, p = id;
while(krg > 0 && p != 0) {
loc.push_back(sh[p]);
p = T[p][0];
krg--;
}
printf("%lld\n", S - krg);
for(int i : loc) {
printf("%d ", i);
}
}
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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |