답안 #91240

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
91240 2018-12-26T15:51:00 Z arman_ferdous 쌀 창고 (IOI11_ricehub) C++17
100 / 100
84 ms 2648 KB
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N = 1e5+10;

int n; ll arr[N], sum[N];

ll get(ll l, ll r, ll M) {
	ll ret = 0;
	if(arr[r] <= M) return (r - l + 1) * M - sum[r] + sum[l-1];
	if(M <= arr[l]) return sum[r] - sum[l-1] - (r - l + 1) * M;
	int p = lower_bound(arr,arr+n,M) - arr;
	return M * (p - l) - sum[p-1] + sum[l-1] + sum[r] - sum[p-1] - M * (r - p + 1);
}

int besthub(int R, int L, int X[], ll B) {
	n = R;
	for(int i = 1; i <= n; i++) arr[i] = X[i-1];
	for(int i = 1; i <= n; i++) sum[i] = sum[i-1] + arr[i];

	int lo = 1, hi = n, ans = 1;
	while(lo <= hi) {
		int mid = (lo + hi) >> 1;
		int can = 0;
		for(int i = 1; i + mid - 1 <= n; i++) {
			int med;
			if(mid & 1) med = arr[i + mid/2];
			else med = (arr[i + mid/2] + arr[i + mid/2 + 1]) / 2;
			for(ll M = med - 1; M <= med + 1; M++)
				if(get(i, i + mid - 1, M) <= B) { can = 1; break; }
			if(can) break;
		} 
		if(can) ans = mid, lo = mid + 1;
		else hi = mid - 1;
	} return ans;
}

Compilation message

ricehub.cpp: In function 'll get(ll, ll, ll)':
ricehub.cpp:11:5: warning: unused variable 'ret' [-Wunused-variable]
  ll ret = 0;
     ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 508 KB Output is correct
3 Correct 2 ms 508 KB Output is correct
4 Correct 2 ms 508 KB Output is correct
5 Correct 2 ms 544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 544 KB Output is correct
2 Correct 2 ms 544 KB Output is correct
3 Correct 2 ms 544 KB Output is correct
4 Correct 2 ms 652 KB Output is correct
5 Correct 2 ms 652 KB Output is correct
6 Correct 2 ms 680 KB Output is correct
7 Correct 2 ms 680 KB Output is correct
8 Correct 2 ms 680 KB Output is correct
9 Correct 2 ms 680 KB Output is correct
10 Correct 2 ms 680 KB Output is correct
11 Correct 2 ms 680 KB Output is correct
12 Correct 2 ms 680 KB Output is correct
13 Correct 2 ms 680 KB Output is correct
14 Correct 2 ms 680 KB Output is correct
15 Correct 2 ms 680 KB Output is correct
16 Correct 2 ms 680 KB Output is correct
17 Correct 2 ms 680 KB Output is correct
18 Correct 2 ms 680 KB Output is correct
19 Correct 2 ms 680 KB Output is correct
20 Correct 2 ms 680 KB Output is correct
21 Correct 2 ms 680 KB Output is correct
22 Correct 2 ms 680 KB Output is correct
23 Correct 13 ms 680 KB Output is correct
24 Correct 2 ms 680 KB Output is correct
25 Correct 2 ms 680 KB Output is correct
26 Correct 2 ms 680 KB Output is correct
27 Correct 2 ms 680 KB Output is correct
28 Correct 2 ms 680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 680 KB Output is correct
2 Correct 2 ms 680 KB Output is correct
3 Correct 2 ms 680 KB Output is correct
4 Correct 2 ms 680 KB Output is correct
5 Correct 2 ms 680 KB Output is correct
6 Correct 2 ms 680 KB Output is correct
7 Correct 2 ms 680 KB Output is correct
8 Correct 2 ms 680 KB Output is correct
9 Correct 2 ms 680 KB Output is correct
10 Correct 2 ms 680 KB Output is correct
11 Correct 2 ms 680 KB Output is correct
12 Correct 2 ms 680 KB Output is correct
13 Correct 2 ms 680 KB Output is correct
14 Correct 2 ms 712 KB Output is correct
15 Correct 2 ms 712 KB Output is correct
16 Correct 2 ms 712 KB Output is correct
17 Correct 2 ms 712 KB Output is correct
18 Correct 2 ms 712 KB Output is correct
19 Correct 2 ms 712 KB Output is correct
20 Correct 2 ms 712 KB Output is correct
21 Correct 4 ms 712 KB Output is correct
22 Correct 4 ms 712 KB Output is correct
23 Correct 2 ms 712 KB Output is correct
24 Correct 2 ms 712 KB Output is correct
25 Correct 2 ms 712 KB Output is correct
26 Correct 2 ms 712 KB Output is correct
27 Correct 5 ms 728 KB Output is correct
28 Correct 5 ms 728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 1020 KB Output is correct
2 Correct 31 ms 1020 KB Output is correct
3 Correct 15 ms 2556 KB Output is correct
4 Correct 16 ms 2648 KB Output is correct
5 Correct 42 ms 2648 KB Output is correct
6 Correct 41 ms 2648 KB Output is correct
7 Correct 13 ms 2648 KB Output is correct
8 Correct 13 ms 2648 KB Output is correct
9 Correct 47 ms 2648 KB Output is correct
10 Correct 51 ms 2648 KB Output is correct
11 Correct 17 ms 2648 KB Output is correct
12 Correct 17 ms 2648 KB Output is correct
13 Correct 84 ms 2648 KB Output is correct
14 Correct 81 ms 2648 KB Output is correct
15 Correct 13 ms 2648 KB Output is correct
16 Correct 13 ms 2648 KB Output is correct
17 Correct 15 ms 2648 KB Output is correct
18 Correct 15 ms 2648 KB Output is correct
19 Correct 16 ms 2648 KB Output is correct
20 Correct 16 ms 2648 KB Output is correct