답안 #806813

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
806813 2023-08-04T10:02:49 Z Gangsta 쌀 창고 (IOI11_ricehub) C++14
100 / 100
19 ms 2736 KB
// a >> b = a / pow(2,b)
// a << b = a * pow(2,b)
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define sz size()
#define ss second
#define ff first
#define N 200001
#define pll pair<ll,ll>

using namespace std;

bool check(int md, ll b, vector<int>arr){
	int n = arr.sz, p = (md-1) / 2;
	ll cost = 0;
	for(int i = 0; i < md; i++) cost += abs(arr[p] - arr[i]);
	if(cost <= b) return true;
	for(int i = md; i < n; i++){
		int x = arr[i - md], y = arr[i];
		int m = arr[p], mp = arr[p+1];
		p++;
		if(md&1){
			cost += x + y;
			cost -= m + mp;
		}
		else{
			cost += x + y;
			cost -= mp + mp;
		}
		if(cost <= b) return true;
	}
	return false;
}

int besthub(int r, int l, int x[N], ll b){
	vector <int> arr;
	for(int i = 0; i < r; i++) arr.pb(x[i]);
	int st = 1, en = r, md = 0, answer = -1;
	while(st <= en){
		md = (st + en) >> 1;
		if(check(md, b, arr)){
			answer = md;
			st = md + 1;
		}
		else en = md - 1;
	}
	return answer;
}

//int main(){
//	ll r, l, x[N], b;
//	cin >> r >> l;
//	for(int i = 0; i < r; i++) cin >> x[i];
//	cin >> b;
//	cout << besthub(r,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 1 ms 212 KB Output is correct
4 Correct 0 ms 312 KB Output is correct
5 Correct 1 ms 312 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 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 308 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 312 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 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 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 308 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 224 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 312 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 328 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 324 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 320 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 724 KB Output is correct
2 Correct 4 ms 724 KB Output is correct
3 Correct 15 ms 2736 KB Output is correct
4 Correct 19 ms 2676 KB Output is correct
5 Correct 6 ms 1360 KB Output is correct
6 Correct 6 ms 1360 KB Output is correct
7 Correct 17 ms 2396 KB Output is correct
8 Correct 14 ms 2296 KB Output is correct
9 Correct 5 ms 1304 KB Output is correct
10 Correct 5 ms 1232 KB Output is correct
11 Correct 12 ms 2636 KB Output is correct
12 Correct 12 ms 2592 KB Output is correct
13 Correct 6 ms 1376 KB Output is correct
14 Correct 6 ms 1360 KB Output is correct
15 Correct 9 ms 2076 KB Output is correct
16 Correct 11 ms 2104 KB Output is correct
17 Correct 11 ms 2320 KB Output is correct
18 Correct 11 ms 2336 KB Output is correct
19 Correct 11 ms 2508 KB Output is correct
20 Correct 12 ms 2480 KB Output is correct