답안 #586337

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
586337 2022-06-30T06:56:37 Z Jomnoi Safety (NOI18_safety) C++17
100 / 100
47 ms 6280 KB
#include <bits/stdc++.h>
using namespace std;

const int MAX_N = 2e5 + 5;

int S[MAX_N];
priority_queue <long long> L;
priority_queue <long long, vector <long long>, greater <long long>> R;

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    int N, H;
    cin >> N >> H;
    
    for(int i = 1; i <= N; i++) {
        cin >> S[i];
    }

    L.push(S[1]);
    R.push(S[1]);
    long long yMin = 0, shift = 0; 
    for(int i = 2; i <= N; i++) {
        shift += H;

        if(S[i] < L.top() - shift) {
            yMin += (L.top() - shift) - S[i];
            R.push(L.top() - 2 * shift);
            L.pop();
            L.push(S[i] + shift);
            L.push(S[i] + shift);
        }
        else if(S[i] > R.top() + shift) {
            yMin += S[i] - (R.top() + shift);
            L.push(R.top() + 2 * shift);
            R.pop();
            R.push(S[i] - shift);
            R.push(S[i] - shift);
        }
        else {
            L.push(S[i] + shift);
            R.push(S[i] - shift);
        }
    }
    cout << yMin;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 280 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 4424 KB Output is correct
2 Correct 45 ms 6032 KB Output is correct
3 Correct 47 ms 6076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 280 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 280 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 328 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 328 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 280 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 328 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 328 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 476 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 480 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 1 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 280 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 328 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 328 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 476 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 2 ms 468 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 480 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 1 ms 504 KB Output is correct
41 Correct 2 ms 468 KB Output is correct
42 Correct 2 ms 424 KB Output is correct
43 Correct 2 ms 512 KB Output is correct
44 Correct 2 ms 468 KB Output is correct
45 Correct 1 ms 472 KB Output is correct
46 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 280 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 30 ms 4424 KB Output is correct
20 Correct 45 ms 6032 KB Output is correct
21 Correct 47 ms 6076 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 328 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 328 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 476 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 2 ms 468 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 480 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 1 ms 504 KB Output is correct
44 Correct 2 ms 468 KB Output is correct
45 Correct 2 ms 424 KB Output is correct
46 Correct 2 ms 512 KB Output is correct
47 Correct 2 ms 468 KB Output is correct
48 Correct 1 ms 472 KB Output is correct
49 Correct 1 ms 468 KB Output is correct
50 Correct 45 ms 6280 KB Output is correct
51 Correct 39 ms 5792 KB Output is correct
52 Correct 28 ms 5668 KB Output is correct
53 Correct 35 ms 6084 KB Output is correct
54 Correct 46 ms 6144 KB Output is correct
55 Correct 28 ms 5816 KB Output is correct
56 Correct 33 ms 6072 KB Output is correct
57 Correct 28 ms 5816 KB Output is correct
58 Correct 27 ms 5048 KB Output is correct
59 Correct 34 ms 6104 KB Output is correct