답안 #856164

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
856164 2023-10-02T18:20:51 Z aykhn 쌀 창고 (IOI11_ricehub) C++14
100 / 100
12 ms 4208 KB
#include "ricehub.h"
#include <bits/stdc++.h>

// author : aykhn

using namespace std;
typedef long long ll;

#define pb push_back
#define ins insert
#define mpr make_pair
#define all(v) v.begin(), v.end()
#define bpc __builtin_popcount
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define infll 0x3F3F3F3F3F3F3F3F
#define inf 0x3F3F3F3F

vector<ll> pref;

ll getsum(int l, int r)
{
	return pref[r] - pref[l - 1];
}

int besthub(int n, int L, int X[], ll b)
{
	ll x[n + 1];
	pref.assign(n + 1, 0);
	for (int i = 1; i <= n; i++) x[i] = X[i - 1];
	for (int i = 1; i <= n; i++) pref[i] = pref[i - 1] + x[i];
	int ans = 1;
	for (int i = 1; i <= n; i++)
	{
		int l = 1;
		int r = min(i - 1, n - i);
		int best = 0;
		while (l <= r)
		{
			int mid = (l + r) >> 1;
			if (getsum(i + 1, i + mid) - getsum(i - mid, i - 1) <= b)
			{
				best = mid;
				l = mid + 1;
			}
			else r = mid - 1;
		}
		ll sum = getsum(i + 1, i + best) - getsum(i - best, i - 1);
		if (i - best - 1 >= 1 && sum + x[i] - x[i - best - 1] <= b) ans = max(ans, best * 2 + 2);
		else if (i + best + 1 <= n && sum + x[i + best + 1] - x[i] <= b) ans = max(ans, best * 2 + 2);
		else ans = max(ans, best * 2 + 1);
	}
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 500 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 428 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 452 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 3 ms 776 KB Output is correct
3 Correct 12 ms 4188 KB Output is correct
4 Correct 12 ms 4188 KB Output is correct
5 Correct 6 ms 3420 KB Output is correct
6 Correct 6 ms 3420 KB Output is correct
7 Correct 11 ms 4188 KB Output is correct
8 Correct 11 ms 4208 KB Output is correct
9 Correct 6 ms 3420 KB Output is correct
10 Correct 6 ms 3280 KB Output is correct
11 Correct 12 ms 4056 KB Output is correct
12 Correct 12 ms 4188 KB Output is correct
13 Correct 6 ms 3420 KB Output is correct
14 Correct 7 ms 3564 KB Output is correct
15 Correct 9 ms 3676 KB Output is correct
16 Correct 9 ms 3676 KB Output is correct
17 Correct 10 ms 3932 KB Output is correct
18 Correct 11 ms 3932 KB Output is correct
19 Correct 11 ms 3932 KB Output is correct
20 Correct 11 ms 3928 KB Output is correct