# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
339922 |
2020-12-26T11:04:40 Z |
Sho10 |
Rice Hub (IOI11_ricehub) |
C++14 |
|
33 ms |
4204 KB |
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#include "ricehub.h"
#define ll long long
#define double long double
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005ll
#define CODE_START ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,pref[200005],suf[200005],a[200005];
ll calc1(ll i,ll j){
return pref[j]-pref[i]-i*(a[j]-a[i]);
}
ll calc2(ll i,ll j){
return suf[i]-suf[j]-(n-j-1)*(a[j]-a[i]);
}
int32_t besthub(int32_t R,int32_t L,int32_t X[],ll B){
n=R;
for(ll i=0;i<n;i++)
{
a[i]=X[i];
if(i>0){
pref[i]=pref[i-1]+i*(a[i]-a[i-1]);
}
}
for(ll i=n-1;i>=0;i--)
{
if(i<n-1){
suf[i]=suf[i+1]+(n-i-1)*(a[i+1]-a[i]);
}
}
ll ans=1;
for(ll i=0;i<n;i++){
ll l=0,r=n+1,mid=(l+r)/2;
while(l<r){
mid=(l+r)/2;
ll x=0,y=0;
if(mid%2==1){
x=mid/2;
y=mid/2;
}else {
y=mid/2;
x=mid/2-1;
}
if(x>i||y>(n-i-1)){
r=mid;
continue;
}
ll sum=calc1(i-x,i)+calc2(i,i+y);
if(sum>B){
r=mid;
}else {
l=mid+1;
}
mid=(l+r)/2;
}
ll x=0,y=0;
if(mid%2==1){
x=mid/2;
y=mid/2;
}else {
y=mid/2;
x=mid/2-1;
}
ll sum=calc1(max(0ll,i-x),i)+calc2(i,i+y);
if(sum>B||x>i||y>(n-i-1)){
mid--;
}
ans=max(ans,mid);
}
return ans;
}
/*
int32_t main(){
CODE_START;
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
368 KB |
Output is correct |
13 |
Correct |
1 ms |
512 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
492 KB |
Output is correct |
22 |
Correct |
2 ms |
492 KB |
Output is correct |
23 |
Correct |
2 ms |
492 KB |
Output is correct |
24 |
Correct |
2 ms |
492 KB |
Output is correct |
25 |
Correct |
2 ms |
492 KB |
Output is correct |
26 |
Correct |
2 ms |
492 KB |
Output is correct |
27 |
Correct |
2 ms |
492 KB |
Output is correct |
28 |
Correct |
2 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
876 KB |
Output is correct |
2 |
Correct |
6 ms |
1008 KB |
Output is correct |
3 |
Correct |
31 ms |
4104 KB |
Output is correct |
4 |
Correct |
25 ms |
4204 KB |
Output is correct |
5 |
Correct |
14 ms |
2028 KB |
Output is correct |
6 |
Correct |
11 ms |
2028 KB |
Output is correct |
7 |
Correct |
26 ms |
3820 KB |
Output is correct |
8 |
Correct |
22 ms |
3820 KB |
Output is correct |
9 |
Correct |
10 ms |
2028 KB |
Output is correct |
10 |
Correct |
13 ms |
2028 KB |
Output is correct |
11 |
Correct |
24 ms |
4076 KB |
Output is correct |
12 |
Correct |
33 ms |
4076 KB |
Output is correct |
13 |
Correct |
11 ms |
2176 KB |
Output is correct |
14 |
Correct |
11 ms |
2156 KB |
Output is correct |
15 |
Correct |
24 ms |
3180 KB |
Output is correct |
16 |
Correct |
24 ms |
3180 KB |
Output is correct |
17 |
Correct |
22 ms |
3692 KB |
Output is correct |
18 |
Correct |
22 ms |
3692 KB |
Output is correct |
19 |
Correct |
32 ms |
3948 KB |
Output is correct |
20 |
Correct |
23 ms |
3948 KB |
Output is correct |