답안 #770579

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
770579 2023-07-01T13:33:28 Z ByeWorld 쌀 창고 (IOI11_ricehub) C++14
100 / 100
13 ms 2940 KB
#include "ricehub.h"
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
typedef pair<int,int> pii;
typedef pair<pii, int> ipii;
const int MAXN = 1e5+100;
const ll INF = 2e18+10;

int n; ll b;
int a[MAXN]; ll pref[MAXN];

bool cost(int cnt){
	ll mn = INF;
	for(int l = 1; l+cnt-1 <= n; l++){
		int r = l + cnt-1; int mid = ((l+r+1)>>1);
		if((pref[r]-pref[mid-1]) - 1ll*(r-mid+1)*a[mid] + (1ll*(mid-l)*a[mid])-(pref[mid-1]-pref[l-1]) <= b) return 1;
	}
	return 0;
}

int besthub(int R, int L, int X[], long long B){
	n = R; b = B;
	for(int i=1; i<=n; i++){
		a[i] = X[i-1]; pref[i] = pref[i-1] + a[i];
	}

	int l = 1; int r = n; int mid = 0; int cnt = 0;
	while(l <= r){
		mid = ((l+r)>>1);
		if(cost(mid)){
			cnt = mid; l = mid+1;
		} else r = mid-1;
	}
	return cnt;
}

Compilation message

ricehub.cpp: In function 'bool cost(int)':
ricehub.cpp:18:5: warning: unused variable 'mn' [-Wunused-variable]
   18 |  ll mn = INF;
      |     ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 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 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 ms 212 KB Output is correct
5 Correct 1 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 0 ms 212 KB Output is correct
9 Correct 0 ms 304 KB Output is correct
10 Correct 0 ms 304 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 312 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 304 KB Output is correct
17 Correct 1 ms 308 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 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 0 ms 300 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 308 KB Output is correct
6 Correct 0 ms 304 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 308 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 312 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 352 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 316 KB Output is correct
26 Correct 1 ms 340 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 768 KB Output is correct
2 Correct 2 ms 772 KB Output is correct
3 Correct 10 ms 2828 KB Output is correct
4 Correct 10 ms 2880 KB Output is correct
5 Correct 5 ms 1364 KB Output is correct
6 Correct 5 ms 1360 KB Output is correct
7 Correct 10 ms 2652 KB Output is correct
8 Correct 9 ms 2536 KB Output is correct
9 Correct 5 ms 1364 KB Output is correct
10 Correct 5 ms 1364 KB Output is correct
11 Correct 10 ms 2940 KB Output is correct
12 Correct 10 ms 2852 KB Output is correct
13 Correct 6 ms 1452 KB Output is correct
14 Correct 6 ms 1376 KB Output is correct
15 Correct 7 ms 2260 KB Output is correct
16 Correct 7 ms 2260 KB Output is correct
17 Correct 13 ms 2644 KB Output is correct
18 Correct 13 ms 2616 KB Output is correct
19 Correct 10 ms 2768 KB Output is correct
20 Correct 9 ms 2788 KB Output is correct