Submission #344295

# Submission time Handle Problem Language Result Execution time Memory
344295 2021-01-05T12:49:37 Z NicolaAbusaad2014 Rice Hub (IOI11_ricehub) C++14
100 / 100
38 ms 4192 KB
/**
 * Prof.Nicola
**/
#include "ricehub.h"
#include <bits/stdc++.h>

using namespace std;
template<class T>void re(T&x){cin>>x;}
template<class T1,class T2> void re(pair<T1,T2>&x){re(x.first);re(x.second);}
template<class T>void re(vector<T>&x){for(long i=0;i<x.size();i++){re(x[i]);}}
template<class T>void re(deque<T>&x){for(long i=0;i<x.size();i++){re(x[i]);}}
template<class T1,class T2> pair<T1,T2> mp(T1&x,T2&z){return make_pair(x,z);}
vector<long long>v,pre;
long long cost,n;
long long calc(long long l,long long r)
{
    long long mid=(l+r)/2;
    long long ret=(pre[r+1]-pre[mid+1])-((r-mid)*v[mid])+(((mid-l)*v[mid])-(pre[mid]-pre[l]));
    return ret;
}
long long right(long l,long r)
{
    if(l==r){
        return l;
    }
    long long z=r-l,x=l;
    while(z&(z-1)){
        z=z&(z-1);
    }
    while(z){
        if(x+z<=r&&calc(l,x+z)<=cost){
            x+=z;
        }
        z/=2;
    }
    return x;
}
int besthub(int R, int L, int X[], long long B)
{
    cost=B;
    n=R;
    pre.push_back(0);
    for(long i=0;i<n;i++){
        v.push_back(X[i]);
    }
    for(long i=0;i<n;i++){
        pre.push_back(pre[i]+X[i]);
    }
    int ans=1;
    for(long i=0;i<n;i++){
        ans=max(ans,(int)(right(i,n-1)-i+1));
    }
    return ans;
}
# 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 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 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 492 KB Output is correct
26 Correct 1 ms 492 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 492 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 2 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 1128 KB Output is correct
2 Correct 6 ms 1148 KB Output is correct
3 Correct 35 ms 4192 KB Output is correct
4 Correct 38 ms 4084 KB Output is correct
5 Correct 19 ms 2020 KB Output is correct
6 Correct 16 ms 2020 KB Output is correct
7 Correct 28 ms 3808 KB Output is correct
8 Correct 27 ms 3808 KB Output is correct
9 Correct 15 ms 2020 KB Output is correct
10 Correct 17 ms 2020 KB Output is correct
11 Correct 30 ms 4192 KB Output is correct
12 Correct 37 ms 4192 KB Output is correct
13 Correct 16 ms 2020 KB Output is correct
14 Correct 16 ms 2020 KB Output is correct
15 Correct 22 ms 3552 KB Output is correct
16 Correct 22 ms 3552 KB Output is correct
17 Correct 27 ms 3808 KB Output is correct
18 Correct 26 ms 3808 KB Output is correct
19 Correct 28 ms 3936 KB Output is correct
20 Correct 29 ms 3936 KB Output is correct