답안 #262444

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
262444 2020-08-12T23:47:31 Z c4ts0up 쌀 창고 (IOI11_ricehub) C++17
100 / 100
21 ms 3572 KB
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
ll n;
vector <ll> arr, costos;

ll Cost(ll s, ll t, ll p) {
	return (p-s)*arr[p] - (costos[p]-costos[s]) + (costos[t+1]-costos[p+1]) - (t-p)*arr[p];
}
 
 
int besthub(int R, int L, int X[], ll B) {
	n = R;
	ll lb = 0, ub = n, mid, p;
	
	for (ll i=0; i<R; i++) arr.push_back((ll)X[i]);
	
	
	// precalculamos los costos
	costos.resize(n+1);
	costos[0] = 0LL;
	for (int i=1; i<=n; i++) costos[i] = costos[i-1] + arr[i-1];
	
	
	// O(log R)
	while (lb <= ub) {
		// sacamos el medio
		mid = (lb+ub)/2;
		
		//cerr << "lb = " << lb << ", ub = " << ub << ", mid = " << mid << endl;
		
		bool success = false;
		
		for (int i=0; i+mid<n; i++) {
			
			p = (2LL*i+mid)/2;
			//cerr << "El costo de [" << i << ", " << i+mid << "] es " << Cost(i, i+mid, p) << endl;
			//cerr << "p = " << p << endl;
			if (Cost(i, i+mid, p) <= B) {
				success = true;
				break;
			}
		}
		
		if (success) lb = mid+1;
		else ub = mid-1;
	}
	//cerr << "lb = " << lb << ", ub = " << ub << ", mid = " << mid << endl;
	return ub+1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 1 ms 256 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 0 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 0 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 512 KB Output is correct
22 Correct 1 ms 512 KB Output is correct
23 Correct 1 ms 512 KB Output is correct
24 Correct 2 ms 512 KB Output is correct
25 Correct 1 ms 512 KB Output is correct
26 Correct 1 ms 512 KB Output is correct
27 Correct 2 ms 512 KB Output is correct
28 Correct 1 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1020 KB Output is correct
2 Correct 5 ms 1020 KB Output is correct
3 Correct 20 ms 3572 KB Output is correct
4 Correct 19 ms 3444 KB Output is correct
5 Correct 10 ms 1912 KB Output is correct
6 Correct 10 ms 1784 KB Output is correct
7 Correct 17 ms 3188 KB Output is correct
8 Correct 17 ms 3188 KB Output is correct
9 Correct 9 ms 1656 KB Output is correct
10 Correct 9 ms 1656 KB Output is correct
11 Correct 21 ms 3436 KB Output is correct
12 Correct 21 ms 3444 KB Output is correct
13 Correct 11 ms 1784 KB Output is correct
14 Correct 11 ms 1784 KB Output is correct
15 Correct 16 ms 2676 KB Output is correct
16 Correct 16 ms 2676 KB Output is correct
17 Correct 19 ms 3188 KB Output is correct
18 Correct 21 ms 3188 KB Output is correct
19 Correct 20 ms 3316 KB Output is correct
20 Correct 21 ms 3292 KB Output is correct