Submission #672126

# Submission time Handle Problem Language Result Execution time Memory
672126 2022-12-14T19:35:47 Z Hacv16 Rice Hub (IOI11_ricehub) C++17
100 / 100
11 ms 2388 KB
#include<bits/stdc++.h>
#include "ricehub.h"

#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2")
 
using namespace std;
 
typedef long long ll;
const int MAX = 2e6 + 15;
const ll INF = 5e18 + 15;

ll n, x[MAX], px[MAX], L;
ll b;

ll sum(ll l, ll r){
	return px[r] - (l == 0 ? 0LL : px[l - 1]);
}

bool f(ll s){
	for(ll l = 0, r = s - 1; r < n; l++, r++){
		ll m = (l + r) >> 1, cost = 0; 

		cost += sum(m + 1, r) - (r - m) * x[m];
		cost += (m - l) * x[m] - sum(l, m - 1);

		if(cost <= b) return true; 
	}

	return false;
}

int besthub(int _n, int _L, int _x[], ll _b){
	n = _n; L = _L; b = _b;

	for(int i = 0; i < n; i++)
		x[i] = _x[i];

	for(int i = 1; i < n; i++)
		px[i] = x[i] + px[i - 1];

	ll l = 0, r = MAX, ans = 1;
 
	while(l <= r){ //bbin na resposta
		int m = (l + r) >> 1;
		if(f(m)) l = m + 1, ans = m;
		else r = m - 1;
	}

	return ans;
}
# Verdict Execution time Memory 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 0 ms 212 KB Output is correct
# Verdict Execution time Memory 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 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 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 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 0 ms 212 KB Output is correct
21 Correct 0 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 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 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 340 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
# Verdict Execution time Memory Grader output
1 Correct 3 ms 596 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 10 ms 2256 KB Output is correct
4 Correct 10 ms 2260 KB Output is correct
5 Correct 7 ms 1364 KB Output is correct
6 Correct 6 ms 1364 KB Output is correct
7 Correct 9 ms 2376 KB Output is correct
8 Correct 10 ms 2388 KB Output is correct
9 Correct 8 ms 1492 KB Output is correct
10 Correct 6 ms 1364 KB Output is correct
11 Correct 11 ms 2384 KB Output is correct
12 Correct 11 ms 2320 KB Output is correct
13 Correct 7 ms 1336 KB Output is correct
14 Correct 7 ms 1332 KB Output is correct
15 Correct 8 ms 1876 KB Output is correct
16 Correct 8 ms 1884 KB Output is correct
17 Correct 10 ms 2132 KB Output is correct
18 Correct 11 ms 2152 KB Output is correct
19 Correct 10 ms 2260 KB Output is correct
20 Correct 10 ms 2260 KB Output is correct