Submission #307685

# Submission time Handle Problem Language Result Execution time Memory
307685 2020-09-29T05:23:36 Z juggernaut Rice Hub (IOI11_ricehub) C++14
100 / 100
21 ms 3968 KB
#include"ricehub.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,a[100005];
ll b,pref[100005],suff[100005];
ll pref_calc(ll l,ll r){
    return pref[r]-1ll*(l-1)*(a[r]-a[l-1])-pref[l-1];
}
ll suff_calc(ll l,ll r){
    return suff[l]-1ll*(n-r)*(a[r+1]-a[l])-suff[r+1];
}
bool app(ll l,ll r){
    ll i=(l+r)>>1ll;
    ll mn=pref_calc(l,i)+suff_calc(i,r);
    return mn<=b;
}
bool check(ll x){
    bool flag=0;
    for(ll i=1;i+x-1<=n;i++)flag|=app(i,x+i-1);
    return flag;
}
int besthub(int N,int L,int A[],ll B){
    n=N;b=B;
    for(int i=0;i<n;i++)a[i+1]=A[i];
    for(int i=1;i<=n;i++)
        pref[i]=pref[i-1]+(i-1)*(a[i]-a[i-1]);
    for(int i=n;i>=1;i--)
        suff[i]=suff[i+1]+(n-i)*(a[i+1]-a[i]);
    int l=1,r=n,m;
    while(l<r){
        m=(l+r+1)>>1;
        if(check(m))l=m;
        else r=m-1;
    }
    return l;
}
//#include"grader.cpp"
# 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 0 ms 384 KB Output is correct
5 Correct 0 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 288 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 256 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 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 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 0 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 0 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 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 0 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 0 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 436 KB Output is correct
25 Correct 2 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 896 KB Output is correct
2 Correct 4 ms 896 KB Output is correct
3 Correct 18 ms 3072 KB Output is correct
4 Correct 18 ms 3064 KB Output is correct
5 Correct 10 ms 1664 KB Output is correct
6 Correct 10 ms 1664 KB Output is correct
7 Correct 15 ms 3072 KB Output is correct
8 Correct 17 ms 3072 KB Output is correct
9 Correct 10 ms 1664 KB Output is correct
10 Correct 11 ms 1664 KB Output is correct
11 Correct 19 ms 3072 KB Output is correct
12 Correct 21 ms 3064 KB Output is correct
13 Correct 11 ms 2048 KB Output is correct
14 Correct 11 ms 2048 KB Output is correct
15 Correct 16 ms 3200 KB Output is correct
16 Correct 14 ms 3200 KB Output is correct
17 Correct 17 ms 3712 KB Output is correct
18 Correct 17 ms 3712 KB Output is correct
19 Correct 18 ms 3968 KB Output is correct
20 Correct 18 ms 3968 KB Output is correct