Submission #1023505

# Submission time Handle Problem Language Result Execution time Memory
1023505 2024-07-14T21:49:13 Z avighna Solar Storm (NOI20_solarstorm) C++17
36 / 100
392 ms 209592 KB
#include <iostream>
#include <numeric>
#include <vector>

typedef long long ll;

const ll N = 1e6 + 1;

ll d[N], v[N], left[N], right[N], psum[N];
ll lift[N][20];

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);

  ll n, s, k;
  std::cin >> n >> s >> k;

  for (ll i = 0; i < n - 1; ++i) {
    std::cin >> d[i];
  }
  for (ll i = 0; i < n; ++i) {
    std::cin >> v[i];
  }

  for (ll i = n - 1, j = n - 1, dist = 0; i >= 0; --i) {
    if (i != n - 1) {
      dist += d[i];
    }
    // j is the last index satisfying dist[i...j] <= k
    while (dist > k and j - 1 >= 0) {
      dist -= d[j - 1];
      j--;
    }
    lift[i][0] = j + 1;
    right[i] = j;
  }
  for (ll i = 0, j = 0, dist = 0; i < n; ++i) {
    if (i != 0) {
      dist += d[i - 1];
    }
    while (dist > k and j < n - 1) {
      dist -= d[j];
      j++;
    }
    left[i] = j;
  }
  lift[n][0] = n;
  for (ll bt = 1; bt < 20; ++bt) {
    for (ll i = 0; i <= n; ++i) {
      lift[i][bt] = lift[lift[i][bt - 1]][bt - 1];
    }
  }

  auto binary_lift = [&](ll node, ll k) {
    for (ll bt = 0; bt < 20; ++bt) {
      if (k & (1 << bt)) {
        node = lift[node][bt];
      }
    }
    return node;
  };

  std::partial_sum(v, v + n, psum);
  auto sum = [&](ll l, ll r) {
    ll ans = psum[r];
    if (l - 1 >= 0) {
      ans -= psum[l - 1];
    }
    return ans;
  };

  std::pair<ll, ll> best;
  for (ll i = 0; i < n; ++i) {
    best = std::max(
        best, std::make_pair(sum(left[i], right[binary_lift(i, s - 1)]), i));
  }

  std::vector<ll> ans;
  for (ll i = 0, node = best.second; i < s; ++i, node = lift[node][0]) {
    ans.push_back(node);
  }
  while (!ans.empty() and ans.back() == n) {
    ans.pop_back();
  }
  std::cout << ans.size() << "\n";
  for (auto &i : ans) {
    std::cout << i + 1 << " ";
  }
  std::cout << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 2 ms 2140 KB Output is correct
3 Correct 3 ms 2396 KB Output is correct
4 Correct 1 ms 1372 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 3 ms 2124 KB Output is correct
7 Correct 3 ms 2140 KB Output is correct
8 Correct 3 ms 2396 KB Output is correct
9 Correct 2 ms 1760 KB Output is correct
10 Correct 3 ms 2396 KB Output is correct
11 Correct 3 ms 2396 KB Output is correct
12 Correct 1 ms 1304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 227 ms 175464 KB Output is correct
2 Correct 143 ms 111696 KB Output is correct
3 Correct 152 ms 119636 KB Output is correct
4 Correct 163 ms 130644 KB Output is correct
5 Correct 197 ms 152952 KB Output is correct
6 Correct 274 ms 203972 KB Output is correct
7 Correct 174 ms 134640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 2 ms 2140 KB Output is correct
3 Correct 3 ms 2396 KB Output is correct
4 Correct 1 ms 1372 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 3 ms 2124 KB Output is correct
7 Correct 3 ms 2140 KB Output is correct
8 Correct 3 ms 2396 KB Output is correct
9 Correct 2 ms 1760 KB Output is correct
10 Correct 3 ms 2396 KB Output is correct
11 Correct 3 ms 2396 KB Output is correct
12 Correct 1 ms 1304 KB Output is correct
13 Correct 227 ms 175464 KB Output is correct
14 Correct 143 ms 111696 KB Output is correct
15 Correct 152 ms 119636 KB Output is correct
16 Correct 163 ms 130644 KB Output is correct
17 Correct 197 ms 152952 KB Output is correct
18 Correct 274 ms 203972 KB Output is correct
19 Correct 174 ms 134640 KB Output is correct
20 Correct 152 ms 114000 KB Output is correct
21 Correct 191 ms 139784 KB Output is correct
22 Correct 242 ms 166228 KB Output is correct
23 Correct 210 ms 167784 KB Output is correct
24 Correct 203 ms 153428 KB Output is correct
25 Correct 212 ms 153424 KB Output is correct
26 Correct 156 ms 115024 KB Output is correct
27 Correct 199 ms 146256 KB Output is correct
28 Correct 195 ms 146256 KB Output is correct
29 Correct 283 ms 190032 KB Output is correct
30 Correct 219 ms 155476 KB Output is correct
31 Correct 187 ms 136340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 298 ms 172608 KB Output is correct
2 Correct 153 ms 104020 KB Output is correct
3 Correct 154 ms 111440 KB Output is correct
4 Correct 232 ms 161104 KB Output is correct
5 Correct 206 ms 156240 KB Output is correct
6 Correct 211 ms 162872 KB Output is correct
7 Correct 392 ms 209592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 2 ms 2140 KB Output is correct
3 Correct 3 ms 2396 KB Output is correct
4 Correct 1 ms 1372 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 3 ms 2124 KB Output is correct
7 Correct 3 ms 2140 KB Output is correct
8 Correct 3 ms 2396 KB Output is correct
9 Correct 2 ms 1760 KB Output is correct
10 Correct 3 ms 2396 KB Output is correct
11 Correct 3 ms 2396 KB Output is correct
12 Correct 1 ms 1304 KB Output is correct
13 Correct 3 ms 2392 KB Output is correct
14 Incorrect 2 ms 2136 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 2 ms 2140 KB Output is correct
3 Correct 3 ms 2396 KB Output is correct
4 Correct 1 ms 1372 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 3 ms 2124 KB Output is correct
7 Correct 3 ms 2140 KB Output is correct
8 Correct 3 ms 2396 KB Output is correct
9 Correct 2 ms 1760 KB Output is correct
10 Correct 3 ms 2396 KB Output is correct
11 Correct 3 ms 2396 KB Output is correct
12 Correct 1 ms 1304 KB Output is correct
13 Correct 227 ms 175464 KB Output is correct
14 Correct 143 ms 111696 KB Output is correct
15 Correct 152 ms 119636 KB Output is correct
16 Correct 163 ms 130644 KB Output is correct
17 Correct 197 ms 152952 KB Output is correct
18 Correct 274 ms 203972 KB Output is correct
19 Correct 174 ms 134640 KB Output is correct
20 Correct 152 ms 114000 KB Output is correct
21 Correct 191 ms 139784 KB Output is correct
22 Correct 242 ms 166228 KB Output is correct
23 Correct 210 ms 167784 KB Output is correct
24 Correct 203 ms 153428 KB Output is correct
25 Correct 212 ms 153424 KB Output is correct
26 Correct 156 ms 115024 KB Output is correct
27 Correct 199 ms 146256 KB Output is correct
28 Correct 195 ms 146256 KB Output is correct
29 Correct 283 ms 190032 KB Output is correct
30 Correct 219 ms 155476 KB Output is correct
31 Correct 187 ms 136340 KB Output is correct
32 Correct 232 ms 182612 KB Output is correct
33 Correct 207 ms 139856 KB Output is correct
34 Incorrect 302 ms 192652 KB Output isn't correct
35 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 2 ms 2140 KB Output is correct
3 Correct 3 ms 2396 KB Output is correct
4 Correct 1 ms 1372 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 3 ms 2124 KB Output is correct
7 Correct 3 ms 2140 KB Output is correct
8 Correct 3 ms 2396 KB Output is correct
9 Correct 2 ms 1760 KB Output is correct
10 Correct 3 ms 2396 KB Output is correct
11 Correct 3 ms 2396 KB Output is correct
12 Correct 1 ms 1304 KB Output is correct
13 Correct 227 ms 175464 KB Output is correct
14 Correct 143 ms 111696 KB Output is correct
15 Correct 152 ms 119636 KB Output is correct
16 Correct 163 ms 130644 KB Output is correct
17 Correct 197 ms 152952 KB Output is correct
18 Correct 274 ms 203972 KB Output is correct
19 Correct 174 ms 134640 KB Output is correct
20 Correct 152 ms 114000 KB Output is correct
21 Correct 191 ms 139784 KB Output is correct
22 Correct 242 ms 166228 KB Output is correct
23 Correct 210 ms 167784 KB Output is correct
24 Correct 203 ms 153428 KB Output is correct
25 Correct 212 ms 153424 KB Output is correct
26 Correct 156 ms 115024 KB Output is correct
27 Correct 199 ms 146256 KB Output is correct
28 Correct 195 ms 146256 KB Output is correct
29 Correct 283 ms 190032 KB Output is correct
30 Correct 219 ms 155476 KB Output is correct
31 Correct 187 ms 136340 KB Output is correct
32 Correct 298 ms 172608 KB Output is correct
33 Correct 153 ms 104020 KB Output is correct
34 Correct 154 ms 111440 KB Output is correct
35 Correct 232 ms 161104 KB Output is correct
36 Correct 206 ms 156240 KB Output is correct
37 Correct 211 ms 162872 KB Output is correct
38 Correct 392 ms 209592 KB Output is correct
39 Correct 3 ms 2392 KB Output is correct
40 Incorrect 2 ms 2136 KB Output isn't correct
41 Halted 0 ms 0 KB -