Submission #418355

# Submission time Handle Problem Language Result Execution time Memory
418355 2021-06-05T10:09:26 Z Azimjon Rice Hub (IOI11_ricehub) C++17
100 / 100
16 ms 1196 KB
#include "ricehub.h"
#include <bits/stdc++.h>

using namespace std;

int besthub(int R, int L, int X[], long long B) {
	auto cost = [&](int x, int y) { return abs(X[x] - X[y]); };

	int ans = 1;
	long long pb = 0;
	int l, r;
	l = r = 0;

	for (; l + 1 < R;) {
		while (r + 1 < R) {
			int lm = (l + r) / 2;
			int cm = (l + r + 1) / 2;
			long long cb = pb;

			if (lm != cm) {
				cb += (lm - l + 1) * cost(cm, lm);
				cb -= (r - cm + 1) * cost(cm, lm);
			}

			cb += cost(cm, r + 1);
			// cerr << l << " " << r + 1 << " " << cb << " " << endl;
			if (cb > B)
				break;
			pb = cb;

			r++;
		}

		ans = max(ans, r - l + 1);

		// l++;
		int lm = (l + r) / 2;
		int cm = (l + r + 1) / 2;

		if (lm != cm) {
			pb += (lm - l + 1) * cost(cm, lm);
			pb -= (r - cm + 1) * cost(cm, lm);
		}
		pb -= cost(cm, l);
		l++;
		r = max(r, l);
		// cerr << "-----" << l << " " << r << " " << pb << " " << endl;
	}

	return ans;
}
# 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 204 KB Output is correct
5 Correct 0 ms 204 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 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 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 0 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 0 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory 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 0 ms 204 KB Output is correct
6 Correct 0 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 0 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 0 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 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 332 KB Output is correct
2 Correct 3 ms 332 KB Output is correct
3 Correct 15 ms 632 KB Output is correct
4 Correct 15 ms 588 KB Output is correct
5 Correct 7 ms 828 KB Output is correct
6 Correct 7 ms 844 KB Output is correct
7 Correct 13 ms 1196 KB Output is correct
8 Correct 13 ms 1100 KB Output is correct
9 Correct 7 ms 716 KB Output is correct
10 Correct 7 ms 716 KB Output is correct
11 Correct 16 ms 1164 KB Output is correct
12 Correct 16 ms 1168 KB Output is correct
13 Correct 8 ms 832 KB Output is correct
14 Correct 8 ms 800 KB Output is correct
15 Correct 12 ms 1060 KB Output is correct
16 Correct 13 ms 1004 KB Output is correct
17 Correct 14 ms 1132 KB Output is correct
18 Correct 14 ms 1096 KB Output is correct
19 Correct 14 ms 1088 KB Output is correct
20 Correct 15 ms 1176 KB Output is correct