Submission #226406

# Submission time Handle Problem Language Result Execution time Memory
226406 2020-04-23T18:06:42 Z cfalas Rice Hub (IOI11_ricehub) C++14
100 / 100
29 ms 2560 KB
#include<bits/stdc++.h>
using namespace std;
#include "ricehub.h"
#define ll long long
#define MID ((l+r)/2)


int besthub(int n, int rr, int x[], long long b) {
	ll pre[n+1] = {};
	pre[0] = 0;
	for(int i=0;i<n;i++) pre[i+1] = pre[i] + x[i];
	ll ans=0;
	for(int i=0;i<n;i++){
		ll l=i;
		ll r=n-1;
		ll m, mm;
		while(l<=r){
			m = MID;
			ll mid = (i+m)/2;
			//cout<<"mdian: "<<x[mid]<<endl;
			//cout<<"sum before: "<<pre[mid]-pre[i]<<endl;
			ll c = (mid-i) * x[mid] - pre[mid]+pre[i];
			//cout<<"sum after: "<<pre[m+1]-pre[mid+1]<<endl;
			c+= pre[m+1]-pre[mid+1] - (m-mid) * x[mid];
			//cout<<i<< " "<<m<<" "<<c<<endl;
			if(c>b) r = m-1;
			else mm=m, l=m+1;
		}
		ans = max(ans,mm-i+1);
	}
	return ans;
}

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:29:19: warning: 'mm' may be used uninitialized in this function [-Wmaybe-uninitialized]
   ans = max(ans,mm-i+1);
                 ~~^~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 5 ms 256 KB Output is correct
13 Correct 4 ms 256 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 5 ms 256 KB Output is correct
16 Correct 4 ms 256 KB Output is correct
17 Correct 4 ms 256 KB Output is correct
18 Correct 4 ms 256 KB Output is correct
19 Correct 5 ms 256 KB Output is correct
20 Correct 4 ms 256 KB Output is correct
21 Correct 4 ms 256 KB Output is correct
22 Correct 5 ms 416 KB Output is correct
23 Correct 4 ms 256 KB Output is correct
24 Correct 4 ms 256 KB Output is correct
25 Correct 4 ms 256 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 4 ms 256 KB Output is correct
28 Correct 4 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 256 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 5 ms 256 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 5 ms 256 KB Output is correct
16 Correct 5 ms 256 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 256 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 6 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 6 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 6 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 512 KB Output is correct
2 Correct 17 ms 640 KB Output is correct
3 Correct 27 ms 1536 KB Output is correct
4 Correct 28 ms 1536 KB Output is correct
5 Correct 16 ms 1284 KB Output is correct
6 Correct 15 ms 1280 KB Output is correct
7 Correct 26 ms 2304 KB Output is correct
8 Correct 26 ms 2304 KB Output is correct
9 Correct 16 ms 1152 KB Output is correct
10 Correct 17 ms 1152 KB Output is correct
11 Correct 29 ms 2560 KB Output is correct
12 Correct 29 ms 2552 KB Output is correct
13 Correct 17 ms 1280 KB Output is correct
14 Correct 16 ms 1280 KB Output is correct
15 Correct 22 ms 2048 KB Output is correct
16 Correct 23 ms 2040 KB Output is correct
17 Correct 26 ms 2304 KB Output is correct
18 Correct 26 ms 2304 KB Output is correct
19 Correct 28 ms 2432 KB Output is correct
20 Correct 28 ms 2432 KB Output is correct