답안 #478863

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
478863 2021-10-08T16:15:16 Z nicetrymaza 쌀 창고 (IOI11_ricehub) C++14
100 / 100
17 ms 3208 KB
#include <bits/stdc++.h>
using namespace std;
 
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define add push_back
#define mp make_pair
#define fr first
#define sc second
#define pii pair<int, int>
#define pll pair<long long, long long>
#define filein(a) freopen(a, "r", stdin);
#define fileout(a) freopen(a, "w", stdout);
#define fastio ios_base::sync_with_stdio(false); cin.tie(0);
 
const int N = 100011;
const ll MOD = 1000000007;
 
int besthub(int R, int L, int X[], ll B) {
	if(R == 1) return 1;
	ll a[N], b[N];
	a[0] = 0;
	b[R + 1] = 0;
	for(int i = 1; i <= R; i++) {
		if(i == 1) a[i] = 0;
		else a[i] = a[i - 1] + (ll)(i - 1) * ((ll)X[i - 1] - (ll)X[i - 2]);
	}

	for(int i = R; i >= 1; i--) {
		if(i == R) b[i] = 0;
		else b[i] = b[i + 1] + ((ll)R - i) * ((ll)X[i] - (ll)X[i - 1]);
	}
	ll l = 1, r = R, ans = 1;
	while(l <= r) {
		bool yes = true;
		ll m = (l + r) / 2;
		ll mi = m / 2, mj = (m + 1) / 2;
		for(int i = mi; (i + mj) < R; i++) {
			if(i == 0) {
				if((ll)B >= ((ll)X[i + 1] - (ll)X[i])) {
					ans = 2;
					l = m + 1;
					i = R;
					yes = false;
				}
			}
			else {
				ll c1 = a[i + 1] - a[i - mi + 1] - (ll)(i - mi) * ((ll)X[i] - (ll)X[i - mi]);
				ll c2 = b[i + 1] - b[i + 1 + mj] - (ll)(R - i - 1 - mj) * ((ll)X[i + mj] - (ll)X[i]);
				if((c1 + c2) <= B) {
					ans = m + 1;
					l = m + 1;
					i = R;
					yes = false;
				}
			}
		}
		if(yes) r = m - 1;
	}
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1740 KB Output is correct
2 Correct 1 ms 1740 KB Output is correct
3 Correct 1 ms 1740 KB Output is correct
4 Correct 2 ms 1868 KB Output is correct
5 Correct 2 ms 1740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1740 KB Output is correct
2 Correct 1 ms 1740 KB Output is correct
3 Correct 1 ms 1868 KB Output is correct
4 Correct 1 ms 1868 KB Output is correct
5 Correct 1 ms 1740 KB Output is correct
6 Correct 1 ms 1740 KB Output is correct
7 Correct 1 ms 1868 KB Output is correct
8 Correct 1 ms 1740 KB Output is correct
9 Correct 1 ms 1740 KB Output is correct
10 Correct 1 ms 1868 KB Output is correct
11 Correct 1 ms 1868 KB Output is correct
12 Correct 1 ms 1868 KB Output is correct
13 Correct 1 ms 1740 KB Output is correct
14 Correct 1 ms 1868 KB Output is correct
15 Correct 1 ms 1868 KB Output is correct
16 Correct 1 ms 1868 KB Output is correct
17 Correct 2 ms 1740 KB Output is correct
18 Correct 1 ms 1740 KB Output is correct
19 Correct 1 ms 1868 KB Output is correct
20 Correct 2 ms 1868 KB Output is correct
21 Correct 1 ms 1868 KB Output is correct
22 Correct 1 ms 1740 KB Output is correct
23 Correct 1 ms 1740 KB Output is correct
24 Correct 2 ms 1740 KB Output is correct
25 Correct 2 ms 1740 KB Output is correct
26 Correct 1 ms 1740 KB Output is correct
27 Correct 1 ms 1740 KB Output is correct
28 Correct 1 ms 1740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1740 KB Output is correct
2 Correct 1 ms 1868 KB Output is correct
3 Correct 1 ms 1740 KB Output is correct
4 Correct 1 ms 1868 KB Output is correct
5 Correct 1 ms 1740 KB Output is correct
6 Correct 1 ms 1740 KB Output is correct
7 Correct 1 ms 1868 KB Output is correct
8 Correct 1 ms 1868 KB Output is correct
9 Correct 1 ms 1740 KB Output is correct
10 Correct 2 ms 1868 KB Output is correct
11 Correct 1 ms 1868 KB Output is correct
12 Correct 2 ms 1868 KB Output is correct
13 Correct 1 ms 1740 KB Output is correct
14 Correct 1 ms 1868 KB Output is correct
15 Correct 1 ms 1868 KB Output is correct
16 Correct 1 ms 1740 KB Output is correct
17 Correct 2 ms 1788 KB Output is correct
18 Correct 1 ms 1740 KB Output is correct
19 Correct 1 ms 1868 KB Output is correct
20 Correct 1 ms 1868 KB Output is correct
21 Correct 2 ms 1868 KB Output is correct
22 Correct 2 ms 1868 KB Output is correct
23 Correct 2 ms 1868 KB Output is correct
24 Correct 2 ms 1868 KB Output is correct
25 Correct 2 ms 1868 KB Output is correct
26 Correct 2 ms 1868 KB Output is correct
27 Correct 2 ms 1868 KB Output is correct
28 Correct 2 ms 1868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1868 KB Output is correct
2 Correct 4 ms 1868 KB Output is correct
3 Correct 13 ms 2232 KB Output is correct
4 Correct 13 ms 2252 KB Output is correct
5 Correct 7 ms 1996 KB Output is correct
6 Correct 8 ms 2124 KB Output is correct
7 Correct 11 ms 2256 KB Output is correct
8 Correct 16 ms 2252 KB Output is correct
9 Correct 8 ms 2064 KB Output is correct
10 Correct 9 ms 1996 KB Output is correct
11 Correct 17 ms 2188 KB Output is correct
12 Correct 13 ms 2236 KB Output is correct
13 Correct 8 ms 2336 KB Output is correct
14 Correct 8 ms 2380 KB Output is correct
15 Correct 11 ms 2892 KB Output is correct
16 Correct 10 ms 2876 KB Output is correct
17 Correct 13 ms 3056 KB Output is correct
18 Correct 13 ms 3068 KB Output is correct
19 Correct 14 ms 3208 KB Output is correct
20 Correct 14 ms 3148 KB Output is correct