Submission #514985

# Submission time Handle Problem Language Result Execution time Memory
514985 2022-01-19T00:50:49 Z CrouchingDragon Safety (NOI18_safety) C++17
100 / 100
67 ms 6300 KB
#include <bits/stdc++.h>

template <typename T>
using minpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

constexpr int64_t inf = std::numeric_limits<int64_t>::max() / 2;

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int N, H;
  std::cin >> N >> H;
  std::vector<int> S(N);
  for (int i = 0; i < N; ++i) {
    std::cin >> S[i];
  }
  std::priority_queue<int64_t> left;
  minpq<int64_t> right;
  left.push(-inf);
  right.push(+inf);
  int64_t cost = 0, offset = 0;
  auto add_left = [&](int64_t x) {
    right.push(x - offset);
    int64_t y = right.top() + offset;
    right.pop();
    cost += x - y;
    left.push(y + offset);
  };
  auto add_right = [&](int64_t x) {
    left.push(x + offset);
    int64_t y = left.top() - offset;
    left.pop();
    cost += y - x;
    right.push(y - offset);
  };
  for (int i = 0; i < N; ++i) {
    int64_t x = S[i];
    add_left(x);
    add_right(x);
    offset += H;
  }
  std::cout << cost << '\n';
  exit(0);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 292 KB Output is correct
6 Correct 1 ms 292 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 320 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 4072 KB Output is correct
2 Correct 60 ms 6072 KB Output is correct
3 Correct 66 ms 6196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 292 KB Output is correct
6 Correct 1 ms 292 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 0 ms 320 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 0 ms 336 KB Output is correct
16 Correct 1 ms 208 KB Output is correct
17 Correct 1 ms 208 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 1 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 292 KB Output is correct
6 Correct 1 ms 292 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 0 ms 320 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 0 ms 336 KB Output is correct
16 Correct 1 ms 208 KB Output is correct
17 Correct 1 ms 208 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 1 ms 208 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 0 ms 336 KB Output is correct
22 Correct 1 ms 208 KB Output is correct
23 Correct 0 ms 208 KB Output is correct
24 Correct 0 ms 312 KB Output is correct
25 Correct 0 ms 316 KB Output is correct
26 Correct 1 ms 316 KB Output is correct
27 Correct 0 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 292 KB Output is correct
6 Correct 1 ms 292 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 0 ms 320 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 0 ms 336 KB Output is correct
16 Correct 1 ms 208 KB Output is correct
17 Correct 1 ms 208 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 1 ms 208 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 0 ms 336 KB Output is correct
22 Correct 1 ms 208 KB Output is correct
23 Correct 0 ms 208 KB Output is correct
24 Correct 0 ms 312 KB Output is correct
25 Correct 0 ms 316 KB Output is correct
26 Correct 1 ms 316 KB Output is correct
27 Correct 0 ms 336 KB Output is correct
28 Correct 2 ms 464 KB Output is correct
29 Correct 2 ms 464 KB Output is correct
30 Correct 2 ms 464 KB Output is correct
31 Correct 2 ms 336 KB Output is correct
32 Correct 2 ms 464 KB Output is correct
33 Correct 2 ms 464 KB Output is correct
34 Correct 2 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 292 KB Output is correct
6 Correct 1 ms 292 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 0 ms 320 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 208 KB Output is correct
15 Correct 0 ms 208 KB Output is correct
16 Correct 0 ms 208 KB Output is correct
17 Correct 0 ms 208 KB Output is correct
18 Correct 0 ms 208 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 0 ms 336 KB Output is correct
22 Correct 1 ms 208 KB Output is correct
23 Correct 1 ms 208 KB Output is correct
24 Correct 1 ms 208 KB Output is correct
25 Correct 1 ms 208 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 0 ms 336 KB Output is correct
28 Correct 1 ms 208 KB Output is correct
29 Correct 0 ms 208 KB Output is correct
30 Correct 0 ms 312 KB Output is correct
31 Correct 0 ms 316 KB Output is correct
32 Correct 1 ms 316 KB Output is correct
33 Correct 0 ms 336 KB Output is correct
34 Correct 2 ms 464 KB Output is correct
35 Correct 2 ms 464 KB Output is correct
36 Correct 2 ms 464 KB Output is correct
37 Correct 2 ms 336 KB Output is correct
38 Correct 2 ms 464 KB Output is correct
39 Correct 2 ms 464 KB Output is correct
40 Correct 2 ms 464 KB Output is correct
41 Correct 2 ms 464 KB Output is correct
42 Correct 2 ms 336 KB Output is correct
43 Correct 2 ms 464 KB Output is correct
44 Correct 2 ms 464 KB Output is correct
45 Correct 2 ms 464 KB Output is correct
46 Correct 2 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 292 KB Output is correct
6 Correct 1 ms 292 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 0 ms 320 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 208 KB Output is correct
15 Correct 0 ms 208 KB Output is correct
16 Correct 0 ms 208 KB Output is correct
17 Correct 0 ms 208 KB Output is correct
18 Correct 0 ms 208 KB Output is correct
19 Correct 42 ms 4072 KB Output is correct
20 Correct 60 ms 6072 KB Output is correct
21 Correct 66 ms 6196 KB Output is correct
22 Correct 1 ms 320 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 0 ms 336 KB Output is correct
25 Correct 1 ms 208 KB Output is correct
26 Correct 1 ms 208 KB Output is correct
27 Correct 1 ms 208 KB Output is correct
28 Correct 1 ms 208 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 0 ms 336 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 0 ms 208 KB Output is correct
33 Correct 0 ms 312 KB Output is correct
34 Correct 0 ms 316 KB Output is correct
35 Correct 1 ms 316 KB Output is correct
36 Correct 0 ms 336 KB Output is correct
37 Correct 2 ms 464 KB Output is correct
38 Correct 2 ms 464 KB Output is correct
39 Correct 2 ms 464 KB Output is correct
40 Correct 2 ms 336 KB Output is correct
41 Correct 2 ms 464 KB Output is correct
42 Correct 2 ms 464 KB Output is correct
43 Correct 2 ms 464 KB Output is correct
44 Correct 2 ms 464 KB Output is correct
45 Correct 2 ms 336 KB Output is correct
46 Correct 2 ms 464 KB Output is correct
47 Correct 2 ms 464 KB Output is correct
48 Correct 2 ms 464 KB Output is correct
49 Correct 2 ms 464 KB Output is correct
50 Correct 66 ms 6300 KB Output is correct
51 Correct 53 ms 5780 KB Output is correct
52 Correct 65 ms 5776 KB Output is correct
53 Correct 65 ms 6132 KB Output is correct
54 Correct 67 ms 6016 KB Output is correct
55 Correct 54 ms 5788 KB Output is correct
56 Correct 59 ms 5968 KB Output is correct
57 Correct 57 ms 5732 KB Output is correct
58 Correct 45 ms 5064 KB Output is correct
59 Correct 62 ms 5976 KB Output is correct