Submission #418353

# Submission time Handle Problem Language Result Execution time Memory
418353 2021-06-05T10:08:23 Z Azimjon Rice Hub (IOI11_ricehub) C++17
68 / 100
15 ms 1100 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;
	int 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;
			int 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 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 2 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 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 332 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 308 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 256 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 304 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 4 ms 284 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 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 304 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 260 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 256 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 308 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 300 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 312 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 2 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 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 460 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 15 ms 836 KB Output is correct
4 Incorrect 15 ms 1100 KB Output isn't correct
5 Halted 0 ms 0 KB -