답안 #807480

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
807480 2023-08-04T17:56:57 Z OrazB 쌀 창고 (IOI11_ricehub) C++14
100 / 100
93 ms 2920 KB
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define ll long long int
#define pii pair <int, int>
#define pb push_back
#define ff first
#define ss second

const int N = 1e5+5;
const ll inf = 1e18;
int P[N];
ll pref[N];

int F(int A, int B, int x){
	int l = A, r = B, pos = A;
	while(l <= r){
		int md = (l+r)>>1;
		if (P[md] <= x){
			pos = md;
			l = md + 1;
		}else r = md - 1;
	}
	return pos;
}

ll solve(int A, int B){
	ll answer = inf;
	int l = P[A], r = P[B];
	while(l <= r){
		int md = (l+r)>>1;	
		int pos = F(A, B, md);
		ll x = pref[pos], y = pref[B]-pref[pos];
		x -= (A ? pref[A-1] : 0);
		x = md*1ll*(pos-A+1)-x;
		y = y-(B-pos)*1ll*md;
		answer = min(answer, x+y);
		if (x > y) r = md - 1;
		else l = md + 1;
	}
	return answer;
}

int besthub(int n, int L, int X[], ll B){
	pref[0] = X[0];
	for (int i = 0; i < n; i++){
		P[i] = X[i];
		if (i) pref[i] = pref[i-1]+X[i];
	}
	int answer = 0, pos = 0;
	for (int i = 0; i < n; i++){
		while(solve(pos, i) > B) pos++;
		answer = max(answer, i-pos+1);
	}
	return answer;
} 

// int main ()
// {
// 	ios::sync_with_stdio(false);
// 	cin.tie(0);
// 	int n, L;
// 	ll B;
// 	cin >> n >> L >> B;
// 	int X[n];
// 	for (int i = 0; i < n; i++) cin >> X[i];
// 	cout << besthub(n, L, X, B);
// }	
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 308 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 312 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 312 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 320 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 0 ms 316 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 312 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 312 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 3 ms 340 KB Output is correct
24 Correct 3 ms 340 KB Output is correct
25 Correct 3 ms 340 KB Output is correct
26 Correct 3 ms 340 KB Output is correct
27 Correct 3 ms 340 KB Output is correct
28 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 724 KB Output is correct
2 Correct 4 ms 724 KB Output is correct
3 Correct 52 ms 2916 KB Output is correct
4 Correct 58 ms 2920 KB Output is correct
5 Correct 10 ms 1364 KB Output is correct
6 Correct 11 ms 1364 KB Output is correct
7 Correct 58 ms 2644 KB Output is correct
8 Correct 58 ms 2632 KB Output is correct
9 Correct 35 ms 1364 KB Output is correct
10 Correct 35 ms 1364 KB Output is correct
11 Correct 93 ms 2892 KB Output is correct
12 Correct 91 ms 2920 KB Output is correct
13 Correct 31 ms 1376 KB Output is correct
14 Correct 31 ms 1476 KB Output is correct
15 Correct 72 ms 2248 KB Output is correct
16 Correct 67 ms 2260 KB Output is correct
17 Correct 83 ms 2640 KB Output is correct
18 Correct 89 ms 2644 KB Output is correct
19 Correct 88 ms 2732 KB Output is correct
20 Correct 87 ms 2784 KB Output is correct