답안 #211556

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
211556 2020-03-20T17:15:18 Z bigg 쌀 창고 (IOI11_ricehub) C++14
100 / 100
34 ms 3456 KB
#include "ricehub.h"
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 112345;

long long int ar[MAXN];
long long sumr[MAXN];
int besthub(int R, int L, int X[], long long B)
{	
	//sumr[0] = X[0]
	for(int i = 1; i <= R; i++){
		ar[i] = X[i - 1];
		sumr[i] = sumr[i - 1] + ar[i];

	}
	long long int ans = 0;
	for(int i = 1; i <= R; i++){
		long long int l = i, r = R, j; 
		while(r - l >= 0){
			long long int mid = (l + r)/2;
			long long int mid2 = (i + mid)/2;
			long long cost = ar[mid2] * (mid2 - i + 1) - (sumr[mid2] - sumr[i - 1])
				+ (sumr[mid] - sumr[mid2]) -  ar[mid2] * (mid - mid2);
			if(cost <= B){
				j = mid; l = mid + 1;
			}else
				r = mid - 1;

		}
		ans = max(ans, j - i + 1);
	}
	return (int) ans;

}
 

// int r, l, x[MAXN];
// long long b;

//  int main(){
//  	scanf("%d %d %lld", &r, &l, &b);
//  	for(int i = 0; i < r; i++){
//  		scanf("%d", &x[i] );
//  	}
//  	printf("%d\n", besthub(r, l, x, b));


//  }

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:30:20: warning: 'j' may be used uninitialized in this function [-Wmaybe-uninitialized]
   ans = max(ans, j - i + 1);
                  ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 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 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 4 ms 384 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 4 ms 384 KB Output is correct
25 Correct 5 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 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 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 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 512 KB Output is correct
22 Correct 5 ms 512 KB Output is correct
23 Correct 5 ms 512 KB Output is correct
24 Correct 5 ms 512 KB Output is correct
25 Correct 5 ms 512 KB Output is correct
26 Correct 5 ms 512 KB Output is correct
27 Correct 5 ms 512 KB Output is correct
28 Correct 6 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 768 KB Output is correct
2 Correct 8 ms 896 KB Output is correct
3 Correct 26 ms 3328 KB Output is correct
4 Correct 26 ms 3328 KB Output is correct
5 Correct 13 ms 1664 KB Output is correct
6 Correct 14 ms 1664 KB Output is correct
7 Correct 24 ms 3072 KB Output is correct
8 Correct 23 ms 3072 KB Output is correct
9 Correct 14 ms 1664 KB Output is correct
10 Correct 14 ms 1792 KB Output is correct
11 Correct 27 ms 3328 KB Output is correct
12 Correct 27 ms 3456 KB Output is correct
13 Correct 14 ms 1792 KB Output is correct
14 Correct 15 ms 1792 KB Output is correct
15 Correct 23 ms 2560 KB Output is correct
16 Correct 21 ms 2560 KB Output is correct
17 Correct 25 ms 3072 KB Output is correct
18 Correct 25 ms 3064 KB Output is correct
19 Correct 26 ms 3200 KB Output is correct
20 Correct 34 ms 3320 KB Output is correct