Submission #261540

# Submission time Handle Problem Language Result Execution time Memory
261540 2020-08-11T20:43:39 Z oscarsierra12 Rice Hub (IOI11_ricehub) C++14
0 / 100
152 ms 1656 KB
#include "ricehub.h"
#include <stdio.h>
#include <stdlib.h>
#include <iostream>

using namespace std ;

const int N = 2e5 ;

long long ac[N] ;

int besthub(int R, int L, int X[], long long B)
{
  for ( int i = 1 ; i < R ; ++i ) ac[i] = ac[i-1] + (X[i] - X[i-1]) * i ;
  int ans = 0 ;
  for ( int i = 0 ; i < R ; ++i ) {
    int lw = i, hg = R-1 ;
    while ( lw <= hg ) {
        int mid = (lw + hg) >> 1 ;
        int lw2 = i, hg2 = mid ;
        int mid2 ;
        long long cost ;
        while ( lw2 < hg2 ) {
            mid2 = (lw2 + hg2) >> 1 ;
            cost = ac[mid2] - 1ll * i * (X[mid2] - X[i]) - ac[i] + ac[mid] - 1ll * mid2 * (X[mid] - X[mid2]) - ac[mid2];
            mid2++ ;
            long long cost2 = ac[mid2] - 1ll * i * (X[mid2] - X[i]) - ac[i] + ac[mid] - 1ll * mid2 * (X[mid] - X[mid2]) - ac[mid2];
            if ( cost > cost2 ) lw2 = mid2 ;
            else hg2 = mid2-1 ;
        }
        mid2 = lw2 ;
        cost = ac[mid2] - 1ll * i * (X[mid2] - X[i]) - ac[i] + ac[mid] - 1ll * mid2 * (X[mid] - X[mid2]) - ac[mid2];
       // cout << i << " " << mid << " cost " << cost << " = " << ac[mid2] - 1ll * i * (X[mid2] - X[i])  << " + " << ac[mid] - 1ll * mid2 * (X[mid] - X[mid2]) << endl ;
        if ( cost <= B ) lw = mid+1 ;
        else hg = mid-1 ;
    }
   // cout << i << " " << hg << endl ;
    ans = max ( ans, hg - i + 1 ) ;
  }
  return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Incorrect 0 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Incorrect 0 ms 384 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 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 1 ms 512 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Incorrect 1 ms 384 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 512 KB Output is correct
2 Correct 15 ms 512 KB Output is correct
3 Correct 147 ms 1548 KB Output is correct
4 Correct 152 ms 1656 KB Output is correct
5 Incorrect 65 ms 896 KB Output isn't correct
6 Halted 0 ms 0 KB -