답안 #404870

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
404870 2021-05-15T07:56:05 Z SeDunion Safety (NOI18_safety) C++17
33 / 100
2000 ms 464 KB
#include<bits/stdc++.h>
#ifndef LOCAL
#define cerr if(false)cerr
#endif // LOCAL
using namespace std;
using ll = long long;
const int N = 1e6 + 66;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	int n; ll d;
	cin >> n >> d;
	priority_queue<ll, vector<ll>, greater<ll>>R;
	priority_queue<ll>L;
	ll ans = 0;
	for (int i = 0 ; i < n ; ++ i) {
		ll x;
		cin >> x;
		{
			auto C = L;
			while (C.size()) C.pop();
			while (L.size()) {
				C.push(L.top() - d), L.pop();
			}
			L = C;
		}
		{
			auto C = R;
			while (C.size()) C.pop();
			while (R.size()) {
				C.push(R.top() + d), R.pop();
			}
			R = C;
		}
		if (i == 0) {
			L.push(x);
			R.push(x);
			continue;
		}
		if (L.top() <= x && x <= R.top()) {
			L.push(x);
			R.push(x);
		} else if (L.top() > x) {
			assert(x <= R.top());
			ans += L.top() - x;
			R.push(L.top());
			L.pop();
			L.push(x);
			L.push(x);
		} else { // R.top() < x
			assert(x >= L.top());
			ans += x - R.top();
			L.push(R.top());
			R.pop();
			R.push(x);
			R.push(x);
		}
	}
	cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 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 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 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 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2092 ms 364 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 29 ms 360 KB Output is correct
14 Correct 26 ms 412 KB Output is correct
15 Correct 25 ms 332 KB Output is correct
16 Correct 27 ms 344 KB Output is correct
17 Correct 20 ms 368 KB Output is correct
18 Correct 15 ms 332 KB Output is correct
19 Correct 31 ms 332 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 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 29 ms 360 KB Output is correct
14 Correct 26 ms 412 KB Output is correct
15 Correct 25 ms 332 KB Output is correct
16 Correct 27 ms 344 KB Output is correct
17 Correct 20 ms 368 KB Output is correct
18 Correct 15 ms 332 KB Output is correct
19 Correct 31 ms 332 KB Output is correct
20 Correct 23 ms 368 KB Output is correct
21 Correct 29 ms 368 KB Output is correct
22 Correct 19 ms 332 KB Output is correct
23 Correct 15 ms 360 KB Output is correct
24 Correct 25 ms 332 KB Output is correct
25 Correct 16 ms 324 KB Output is correct
26 Correct 26 ms 364 KB Output is correct
27 Correct 23 ms 368 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 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 29 ms 360 KB Output is correct
14 Correct 26 ms 412 KB Output is correct
15 Correct 25 ms 332 KB Output is correct
16 Correct 27 ms 344 KB Output is correct
17 Correct 20 ms 368 KB Output is correct
18 Correct 15 ms 332 KB Output is correct
19 Correct 31 ms 332 KB Output is correct
20 Correct 23 ms 368 KB Output is correct
21 Correct 29 ms 368 KB Output is correct
22 Correct 19 ms 332 KB Output is correct
23 Correct 15 ms 360 KB Output is correct
24 Correct 25 ms 332 KB Output is correct
25 Correct 16 ms 324 KB Output is correct
26 Correct 26 ms 364 KB Output is correct
27 Correct 23 ms 368 KB Output is correct
28 Execution timed out 2079 ms 464 KB Time limit exceeded
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 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 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 29 ms 360 KB Output is correct
20 Correct 26 ms 412 KB Output is correct
21 Correct 25 ms 332 KB Output is correct
22 Correct 27 ms 344 KB Output is correct
23 Correct 20 ms 368 KB Output is correct
24 Correct 15 ms 332 KB Output is correct
25 Correct 31 ms 332 KB Output is correct
26 Correct 23 ms 368 KB Output is correct
27 Correct 29 ms 368 KB Output is correct
28 Correct 19 ms 332 KB Output is correct
29 Correct 15 ms 360 KB Output is correct
30 Correct 25 ms 332 KB Output is correct
31 Correct 16 ms 324 KB Output is correct
32 Correct 26 ms 364 KB Output is correct
33 Correct 23 ms 368 KB Output is correct
34 Execution timed out 2079 ms 464 KB Time limit exceeded
35 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 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 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Execution timed out 2092 ms 364 KB Time limit exceeded
20 Halted 0 ms 0 KB -