답안 #482710

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
482710 2021-10-26T06:21:21 Z mihai145 Safety (NOI18_safety) C++14
100 / 100
231 ms 21060 KB
//
// Created by Mihai145 on 10/25/2021.
//

#include <iostream>
#include <set>

using namespace std;

int N, H, x;
long long ans;

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

    cin >> N >> H >> x;

    multiset<long long> lefts, rights;
    lefts.insert(x), rights.insert(x);

    for(int i = 1; i < N; i++) {
        cin >> x;

        long long shift = 1LL * i * H;
        long long lfb = *lefts.rbegin();
        long long lfb_val = lfb - shift;

        long long rb = *rights.begin();
        long long rb_val = rb + shift;

        if(x < lfb_val) {
            ans += (lfb_val - x);
            lefts.insert(x + shift);
            lefts.insert(x + shift);
            lefts.erase(lefts.find(lfb));
            rights.insert(lfb_val - shift);
        } else if(x > rb_val) {
            ans += (x - rb_val);
            rights.insert(x - shift);
            rights.insert(x - shift);
            rights.erase(rights.find(rb));
            lefts.insert(rb_val + shift);
        } else {
            lefts.insert(x + shift);
            rights.insert(x - shift);
        }
    }

    cout << ans << '\n';

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 316 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 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 308 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 136 ms 12532 KB Output is correct
2 Correct 215 ms 19592 KB Output is correct
3 Correct 206 ms 20384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 312 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 316 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 312 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 312 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 312 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 316 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 312 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 312 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 312 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 312 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 316 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 312 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 312 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 312 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 320 KB Output is correct
28 Correct 3 ms 716 KB Output is correct
29 Correct 3 ms 716 KB Output is correct
30 Correct 3 ms 716 KB Output is correct
31 Correct 2 ms 588 KB Output is correct
32 Correct 2 ms 716 KB Output is correct
33 Correct 3 ms 716 KB Output is correct
34 Correct 2 ms 716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 312 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 316 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 316 KB Output is correct
17 Correct 1 ms 308 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 312 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 312 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 312 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 320 KB Output is correct
34 Correct 3 ms 716 KB Output is correct
35 Correct 3 ms 716 KB Output is correct
36 Correct 3 ms 716 KB Output is correct
37 Correct 2 ms 588 KB Output is correct
38 Correct 2 ms 716 KB Output is correct
39 Correct 3 ms 716 KB Output is correct
40 Correct 2 ms 716 KB Output is correct
41 Correct 3 ms 716 KB Output is correct
42 Correct 3 ms 716 KB Output is correct
43 Correct 2 ms 708 KB Output is correct
44 Correct 3 ms 716 KB Output is correct
45 Correct 2 ms 708 KB Output is correct
46 Correct 2 ms 712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 312 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 316 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 316 KB Output is correct
17 Correct 1 ms 308 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 136 ms 12532 KB Output is correct
20 Correct 215 ms 19592 KB Output is correct
21 Correct 206 ms 20384 KB Output is correct
22 Correct 1 ms 312 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 312 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 312 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 320 KB Output is correct
37 Correct 3 ms 716 KB Output is correct
38 Correct 3 ms 716 KB Output is correct
39 Correct 3 ms 716 KB Output is correct
40 Correct 2 ms 588 KB Output is correct
41 Correct 2 ms 716 KB Output is correct
42 Correct 3 ms 716 KB Output is correct
43 Correct 2 ms 716 KB Output is correct
44 Correct 3 ms 716 KB Output is correct
45 Correct 3 ms 716 KB Output is correct
46 Correct 2 ms 708 KB Output is correct
47 Correct 3 ms 716 KB Output is correct
48 Correct 2 ms 708 KB Output is correct
49 Correct 2 ms 712 KB Output is correct
50 Correct 231 ms 21060 KB Output is correct
51 Correct 171 ms 17408 KB Output is correct
52 Correct 95 ms 16748 KB Output is correct
53 Correct 120 ms 19500 KB Output is correct
54 Correct 117 ms 20076 KB Output is correct
55 Correct 94 ms 17084 KB Output is correct
56 Correct 105 ms 18736 KB Output is correct
57 Correct 98 ms 17136 KB Output is correct
58 Correct 106 ms 14476 KB Output is correct
59 Correct 109 ms 18992 KB Output is correct