Submission #334598

# Submission time Handle Problem Language Result Execution time Memory
334598 2020-12-09T14:42:37 Z sahil_k Rice Hub (IOI11_ricehub) C++14
100 / 100
25 ms 1900 KB
#include "ricehub.h"
#include <iostream>
#include <cmath>
using namespace std;
bool check (int n, int pos[], long long b, int len) {
	long long total = 0;
	for (int i=0; i<len; i++) {
		total += abs(pos[i]-pos[len/2]);
	}
	if (total <= b) return true;
	for (int i=0; i<n-len; i++) {
		total -= pos[len/2+i]-pos[i];
		total += pos[i+len]-pos[len/2+i+1];
		if (len%2 == 0) total += pos[len/2+i+1]-pos[len/2+i];
		if (total <= b) return true;
	}
	return false;
}
int besthub (int n, int max_x, int pos[], long long b) {
	int o;
	int l = 1, r = n, m;
	while (l <= r) {
		m = (l+r)/2;
		bool ans = check(n, pos, b, m);
		if (ans) {
			o = m;
			l = m+1;
		} else {
			r = m-1;
		}
	}
	return o;
}

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:32:9: warning: 'o' may be used uninitialized in this function [-Wmaybe-uninitialized]
   32 |  return o;
      |         ^
# 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 1 ms 364 KB Output is correct
5 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 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 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 364 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 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 1 ms 364 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 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 364 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 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 492 KB Output is correct
2 Correct 4 ms 492 KB Output is correct
3 Correct 18 ms 1772 KB Output is correct
4 Correct 17 ms 1792 KB Output is correct
5 Correct 8 ms 876 KB Output is correct
6 Correct 8 ms 876 KB Output is correct
7 Correct 15 ms 1516 KB Output is correct
8 Correct 15 ms 1516 KB Output is correct
9 Correct 12 ms 748 KB Output is correct
10 Correct 7 ms 748 KB Output is correct
11 Correct 17 ms 1772 KB Output is correct
12 Correct 17 ms 1900 KB Output is correct
13 Correct 8 ms 876 KB Output is correct
14 Correct 8 ms 876 KB Output is correct
15 Correct 13 ms 1388 KB Output is correct
16 Correct 13 ms 1388 KB Output is correct
17 Correct 15 ms 1644 KB Output is correct
18 Correct 25 ms 1644 KB Output is correct
19 Correct 16 ms 1644 KB Output is correct
20 Correct 16 ms 1644 KB Output is correct