Submission #224516

#TimeUsernameProblemLanguageResultExecution timeMemory
224516NightlightSolar Storm (NOI20_solarstorm)C++14
100 / 100
984 ms243836 KiB
#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)

SolarStorm.cpp: In function 'int main()':
SolarStorm.cpp:24:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld %lld", &N, &S, &K);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SolarStorm.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld", &pos[i]);
     ~~~~~^~~~~~~~~~~~~~~~~
SolarStorm.cpp:30:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld", &pre[i]);
     ~~~~~^~~~~~~~~~~~~~~~~
SolarStorm.cpp:72:16: warning: 'id' may be used uninitialized in this function [-Wmaybe-uninitialized]
   int krg = S, p = id;
                ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...