Submission #322339

#TimeUsernameProblemLanguageResultExecution timeMemory
322339saarang123Solar Storm (NOI20_solarstorm)C++14
10 / 100
2050 ms262148 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int MXN = 1e6 + 2; ll dp[MXN][52]; signed main() { std::ios::sync_with_stdio(0); std::cout.tie(0); std::cin.tie(0); int n, s, k; cin >> n >> s >> k; vector<ll> a(n + 1), d(n + 1); vector<array<ll, 2>> c(n + 1); for(int i = 1; i < n; i++) cin >> d[i]; for(int i = 1; i <= n; i++) cin >> a[i], a[i] += a[i - 1]; //prefix sums vector<ll> p(n + 1); for(int i = 1; i <= n; i++) p[i] = p[i - 1] + d[i - 1]; //cout << "prefix sums: "; //for(int i = 1; i <= n; i++) cout << p[i] << ' '; cout << '\n'; for(int i = 1; i <= n; i++) { int id = lower_bound(p.begin(), p.end(), p[i] + k) - p.begin(); if(id > n || p[id] > p[i] + k) id--; //cout << id << ' '; c[i][0] += a[id] - a[i]; c[i][1] = id + 1; id = lower_bound(p.begin(), p.end(), p[i] - k) - p.begin(); c[i][0] += a[i] - a[id]; if(id) c[i][0] += a[id] - a[id - 1]; //cout << id << ' ' << c[i][0] << '\n'; } for(int i = 1; i <= s; i++) dp[n][i] = a[n] - a[n - 1]; for(int i = n - 1; i; i--) { for(int j = s; j; j--) { int nxt = c[i][1]; dp[i][j] = c[i][0] + dp[nxt][j - 1]; } } //cout << "dp:\n"; //for(int i = 1; i <= n; i++) { for(int j = 0; j <= s; j++) cout << dp[i][j] << ' '; cout << '\n';} ll ans = 0; array<int, 2> best; for(int i = 1; i <= n; i++) { for(int j = 0; j <= s; j++) { if(ans < dp[i][j]) ans = dp[i][j], best = {i, j}; } } vector<int> shield; function<void(int i, int j)> out = [&] (int i, int j) { if(j == 0) return; shield.push_back(i); out(c[i][1], j - 1); }; out(best[0], best[1]); //cout << ans << '\n'; cout << shield.size() << '\n'; for(int x : shield) cout << x << ' '; cout << '\n'; return 0; }

Compilation message (stderr)

SolarStorm.cpp: In function 'int main()':
SolarStorm.cpp:57:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   57 |     for(int x : shield) cout << x << ' '; cout << '\n';
      |     ^~~
SolarStorm.cpp:57:43: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   57 |     for(int x : shield) cout << x << ' '; cout << '\n';
      |                                           ^~~~
SolarStorm.cpp:42:19: warning: 'best.std::array<int, 2>::_M_elems[0]' may be used uninitialized in this function [-Wmaybe-uninitialized]
   42 |     array<int, 2> best;
      |                   ^~~~
SolarStorm.cpp:42:19: warning: 'best.std::array<int, 2>::_M_elems[1]' may be used uninitialized in this function [-Wmaybe-uninitialized]
#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...