Submission #138176

# Submission time Handle Problem Language Result Execution time Memory
138176 2019-07-29T13:57:55 Z MrBrionix Rice Hub (IOI11_ricehub) C++14
100 / 100
21 ms 4216 KB
#include "ricehub.h"
#include <stdio.h>
#include <stdlib.h>
#include<bits/stdc++.h>
using namespace std;
/*
#define MAX_R  1000000

static int R, L;
static long long B;
static int X[MAX_R];
static int solution;

inline 
void my_assert(int e) {if (!e) abort();}

static void read_input()
{
  int i;
  my_assert(3==scanf("%d %d %lld",&R,&L,&B));
  for(i=0; i<R; i++)
    my_assert(1==scanf("%d",&X[i]));
  //my_assert(1==scanf("%d",&solution));
}
*/

int low,up,mid;
long long sum,pre[100005],suff[100005],v[100005],pos;
bool ok;

int besthub(int R, int L, int X[], long long B)
{
    
    for(int i=1;i<=R;i++){
        v[i]=X[i-1];
    }
    
    for(int i=1;i<=R;i++){
        pre[i]=pre[i-1]+v[i];
    }
    
    for(int i=R;i>=1;i--){
        suff[i]=suff[i+1]+(L-v[i]);
    }
    
    low=0;
    up=R+1;
    
    while(up-low>1){
        mid=(up+low)/2;
        ok=false;
        
        
        for(int i=mid;i<=R;i++){
            
            pos=(i+(i-mid+1))/2;
            sum=suff[i-mid+1]-suff[pos]-(L-v[pos])*(pos-(i-mid+1));
            sum+=pre[i]-pre[pos]-v[pos]*(i-pos);
            
            if(sum<=B){
                ok=true;
                break;
            }
        }
        
        if(ok)low=mid;
        else up=mid;
        
    }
      
  return low;
}
/*
int main()
{
  int ans;
  read_input();
  ans = besthub(R,L,X,B);
  
  cout<<ans<<endl;
  
  if(ans==solution)
    printf("Correct.\n");
  else
    printf("Incorrect.  Returned %d instead of %d.\n",ans,solution);

  return 0;
}*/
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 396 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 380 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 380 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 504 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 404 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 504 KB Output is correct
22 Correct 3 ms 504 KB Output is correct
23 Correct 3 ms 504 KB Output is correct
24 Correct 3 ms 504 KB Output is correct
25 Correct 3 ms 504 KB Output is correct
26 Correct 3 ms 504 KB Output is correct
27 Correct 3 ms 504 KB Output is correct
28 Correct 3 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 888 KB Output is correct
2 Correct 6 ms 1016 KB Output is correct
3 Correct 19 ms 4148 KB Output is correct
4 Correct 19 ms 4216 KB Output is correct
5 Correct 11 ms 2088 KB Output is correct
6 Correct 11 ms 2040 KB Output is correct
7 Correct 17 ms 3832 KB Output is correct
8 Correct 17 ms 3832 KB Output is correct
9 Correct 10 ms 2040 KB Output is correct
10 Correct 11 ms 2040 KB Output is correct
11 Correct 21 ms 4088 KB Output is correct
12 Correct 21 ms 4088 KB Output is correct
13 Correct 12 ms 2168 KB Output is correct
14 Correct 13 ms 2040 KB Output is correct
15 Correct 16 ms 3192 KB Output is correct
16 Correct 16 ms 3192 KB Output is correct
17 Correct 19 ms 3704 KB Output is correct
18 Correct 19 ms 3704 KB Output is correct
19 Correct 21 ms 3960 KB Output is correct
20 Correct 20 ms 3960 KB Output is correct