Submission #301378

# Submission time Handle Problem Language Result Execution time Memory
301378 2020-09-17T21:31:17 Z eggag32 Rice Hub (IOI11_ricehub) C++17
100 / 100
19 ms 2944 KB
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x, y) debug(x), debug(y)
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))
const int mxN = 1e5 + 5;

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int n;
ll tot;
int x[mxN];
ll psum[mxN];

bool check(int g){
	if(g == 1) return 1;
	rep(i, n - g + 1){
		//we have the segment [i, i + g)
		int nm = g / 2;
		ll sm = psum[i + nm - 1] - (i ? psum[i - 1] : 0);
		ll sm1 = x[i + nm] * nm;
		ll cur = sm1 - sm;
		ll sm2 = psum[i + g - 1] - psum[i + nm];
		ll sm3 = x[i + nm] * (g - nm - 1);
		cur += sm2 - sm3;
		if(cur <= tot) return 1;
	}
	return 0;
}

int besthub(int R, int L, int X[], ll B){
	n = R;
	tot = B;
	rep(i, n) x[i] = X[i];
	int l = 1, r = n;
	psum[0] = x[0];
	repn(i, 1, n) psum[i] = psum[i - 1] + x[i];
	while(l < r){
		int mid = (l + r + 1) / 2;
		if(check(mid)) l = mid;
		else r = mid - 1;
	}
	return l;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 256 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 372 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 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 0 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory 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 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 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 0 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 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 512 KB Output is correct
26 Correct 2 ms 512 KB Output is correct
27 Correct 1 ms 512 KB Output is correct
28 Correct 1 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 768 KB Output is correct
2 Correct 4 ms 768 KB Output is correct
3 Correct 18 ms 2932 KB Output is correct
4 Correct 18 ms 2908 KB Output is correct
5 Correct 8 ms 1408 KB Output is correct
6 Correct 10 ms 1408 KB Output is correct
7 Correct 14 ms 2688 KB Output is correct
8 Correct 15 ms 2688 KB Output is correct
9 Correct 11 ms 1408 KB Output is correct
10 Correct 8 ms 1408 KB Output is correct
11 Correct 18 ms 2940 KB Output is correct
12 Correct 19 ms 2944 KB Output is correct
13 Correct 9 ms 1536 KB Output is correct
14 Correct 9 ms 1536 KB Output is correct
15 Correct 14 ms 2432 KB Output is correct
16 Correct 16 ms 2304 KB Output is correct
17 Correct 16 ms 2680 KB Output is correct
18 Correct 19 ms 2688 KB Output is correct
19 Correct 17 ms 2808 KB Output is correct
20 Correct 17 ms 2816 KB Output is correct