Submission #318636

# Submission time Handle Problem Language Result Execution time Memory
318636 2020-11-02T14:41:18 Z MetB Safety (NOI18_safety) C++14
100 / 100
123 ms 7164 KB
#include <bits/stdc++.h>
 
#define N 2000001
 
using namespace std;
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
 
const ll INF = 1e18, MOD = 998244353, MOD2 = 1e6 + 3;

ll s, e, h, n, a[N];

priority_queue<ll, vector<ll>> lwing;
priority_queue<ll, vector<ll>, greater<ll>> rwing;

ll solve (string testname) {
	lwing.push (a[0]);
	rwing.push (a[0]);

	ll l = 0, r = 0;
	ll ans = 0;

	for (int i = 1; i < n; i++) {
		l += h, r -= h;
		ll ltop = lwing.top () - l;
		ll rtop = rwing.top () - r;

		if (a[i] < ltop) {
			lwing.pop ();
			lwing.push (a[i] + l), lwing.push (a[i] + l);
			rwing.push (ltop + r);
			ans += abs (a[i] - ltop);
		} else if (rtop < a[i]) {
			rwing.pop ();
			rwing.push (a[i] + r), rwing.push (a[i] + r);
			lwing.push (rtop + l);
			ans += abs (a[i] - rtop);
		} else {
			lwing.push (a[i] + l);
			rwing.push (a[i] + r);
		}
	}

	return ans;
}

int main () {
	/*cin >> s >> e >> h;
	mt19937 rng;
	n = 300;

	while (s <= e) {
		string testname = "test_" + to_string (s++);
		ofstream fout (testname + ".in");
		int lh = uniform_int_distribution<int>(h / 10, max ((int) 1e9, 10 * h))(rng);
		fout << n << '\n' <<  << '\n';
		for (int i = 0; i < n; i++) {
			a[i] = uniform_int_distribution<int>(1, 1000000000)(rng);
			fout << a[i] << ' ';
		}
		fout << endl;
		fout.close ();

	}*/

	cin >> n >> h;

	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	cout << solve ("");
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 80 ms 4580 KB Output is correct
2 Correct 111 ms 5080 KB Output is correct
3 Correct 123 ms 5128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 3 ms 492 KB Output is correct
29 Correct 3 ms 768 KB Output is correct
30 Correct 3 ms 620 KB Output is correct
31 Correct 2 ms 492 KB Output is correct
32 Correct 2 ms 492 KB Output is correct
33 Correct 2 ms 620 KB Output is correct
34 Correct 2 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 0 ms 364 KB Output is correct
17 Correct 0 ms 364 KB Output is correct
18 Correct 0 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 3 ms 492 KB Output is correct
35 Correct 3 ms 768 KB Output is correct
36 Correct 3 ms 620 KB Output is correct
37 Correct 2 ms 492 KB Output is correct
38 Correct 2 ms 492 KB Output is correct
39 Correct 2 ms 620 KB Output is correct
40 Correct 2 ms 492 KB Output is correct
41 Correct 3 ms 620 KB Output is correct
42 Correct 3 ms 492 KB Output is correct
43 Correct 3 ms 620 KB Output is correct
44 Correct 3 ms 620 KB Output is correct
45 Correct 3 ms 620 KB Output is correct
46 Correct 3 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 0 ms 364 KB Output is correct
17 Correct 0 ms 364 KB Output is correct
18 Correct 0 ms 364 KB Output is correct
19 Correct 80 ms 4580 KB Output is correct
20 Correct 111 ms 5080 KB Output is correct
21 Correct 123 ms 5128 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 3 ms 492 KB Output is correct
38 Correct 3 ms 768 KB Output is correct
39 Correct 3 ms 620 KB Output is correct
40 Correct 2 ms 492 KB Output is correct
41 Correct 2 ms 492 KB Output is correct
42 Correct 2 ms 620 KB Output is correct
43 Correct 2 ms 492 KB Output is correct
44 Correct 3 ms 620 KB Output is correct
45 Correct 3 ms 492 KB Output is correct
46 Correct 3 ms 620 KB Output is correct
47 Correct 3 ms 620 KB Output is correct
48 Correct 3 ms 620 KB Output is correct
49 Correct 3 ms 620 KB Output is correct
50 Correct 117 ms 7164 KB Output is correct
51 Correct 98 ms 6480 KB Output is correct
52 Correct 85 ms 6544 KB Output is correct
53 Correct 95 ms 6864 KB Output is correct
54 Correct 112 ms 6904 KB Output is correct
55 Correct 84 ms 6480 KB Output is correct
56 Correct 91 ms 6768 KB Output is correct
57 Correct 85 ms 6548 KB Output is correct
58 Correct 66 ms 5840 KB Output is correct
59 Correct 98 ms 6864 KB Output is correct