Submission #120232

# Submission time Handle Problem Language Result Execution time Memory
120232 2019-06-24T03:30:29 Z joseacaz Rice Hub (IOI11_ricehub) C++17
100 / 100
19 ms 4608 KB
#include "ricehub.h"
#include <bits/stdc++.h>
#define MAXN 100005

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int R, L, X[MAXN];
ll B, dist[MAXN], pre[MAXN], sum[MAXN];

bool solve ( int x )
{
	int mid;
	ll total;

	for ( int i = 1; i + x - 1 <= R; i++ )
	{
		mid = (i + (i + x - 1)) / 2;
		total = ((mid - i) * pre[mid]) - (sum[mid - 1] - sum[i - 1]);
		total += (sum[i + x - 1] - sum[mid]) - ((i + x - 1 - mid) * pre[mid]);
		if ( total <= B )
			return 1;
	}
	return 0;
}

int besthub ( int _r, int _l, int _x[], ll _b )
{
	R = _r;
	L = _l;
	B = _b;
	for ( int i = 1; i <= R; i++ )
		X[i] = _x[i - 1];
	
	X[0] = 0;
	for ( int i = 1; i <= R; i++ )
		dist[i] = X[i] - X[i - 1];
	for ( int i = 1; i <= R; i++ )
		pre[i] = pre[i - 1] + dist[i];
	for ( int i = 1; i <= R; i++ )
		sum[i] = sum[i - 1] + pre[i];
	
	int s = 1, e = R, mid, val, ans;
	while ( s <= e )
	{
		mid = (s + e) / 2;
		val = solve ( mid );
		
		if ( val )
			ans = mid, s = mid + 1;
		else
			e = mid - 1;
	}
	
	return ans;
}

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, ll)':
ricehub.cpp:56:9: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
  return ans;
         ^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 372 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 3 ms 512 KB Output is correct
22 Correct 3 ms 640 KB Output is correct
23 Correct 3 ms 512 KB Output is correct
24 Correct 3 ms 512 KB Output is correct
25 Correct 4 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1024 KB Output is correct
2 Correct 5 ms 1152 KB Output is correct
3 Correct 17 ms 4576 KB Output is correct
4 Correct 18 ms 4608 KB Output is correct
5 Correct 10 ms 2304 KB Output is correct
6 Correct 9 ms 2304 KB Output is correct
7 Correct 15 ms 4224 KB Output is correct
8 Correct 15 ms 4224 KB Output is correct
9 Correct 9 ms 2176 KB Output is correct
10 Correct 9 ms 2176 KB Output is correct
11 Correct 19 ms 4472 KB Output is correct
12 Correct 18 ms 4480 KB Output is correct
13 Correct 10 ms 2304 KB Output is correct
14 Correct 11 ms 2304 KB Output is correct
15 Correct 15 ms 3584 KB Output is correct
16 Correct 14 ms 3456 KB Output is correct
17 Correct 17 ms 4140 KB Output is correct
18 Correct 16 ms 4096 KB Output is correct
19 Correct 18 ms 4352 KB Output is correct
20 Correct 17 ms 4352 KB Output is correct