Submission #261566

# Submission time Handle Problem Language Result Execution time Memory
261566 2020-08-11T21:24:56 Z oscarsierra12 Rice Hub (IOI11_ricehub) C++14
0 / 100
1000 ms 26872 KB
#include "ricehub.h"
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <map>
using namespace std ;

const int N = 2e5 ;

long long ac[N], ac2[N] ;
map<int,int> ap;

int besthub(int R, int L, int X[], long long B)
{
  for ( int i = 0 ; i < R ; ++i ) ap[X[i]] = i ;
  for ( int i = 1 ; i < R ; ++i ) ac[i] = ac[i-1] + 1ll * (X[i] - X[i-1]) * i;
  for ( int i = R-2 ; i >= 0 ; --i ) ac2[i] = ac2[i+1] + 1ll * (X[i+1] - X[i]) * (R-i-1) ;
  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 = X[i], hg2 = L ;
        int mid2 ;
        long long cost ;
        while ( lw2 < hg2 ) {
            int mid2a = (lw2 + hg2) >> 1 ;
            mid2 = ap[mid2a] ;
            cost = ac[mid2] - 1ll * i * (X[mid2] - X[i]) - ac[i] + ac2[mid2] - 1ll * (R-mid-1) * (X[mid] - X[mid2]) - ac2[mid];
            mid2a++ ;
            mid2 = ap[mid2a] ;
            long long cost2 = ac[mid2] - 1ll * i * (X[mid2] - X[i]) - ac[i] + ac2[mid2] - 1ll * (R-mid-1) * (X[mid] - X[mid2]) - ac2[mid];
           // cout << i << " " << mid2 << " " <<mid << " cost " << cost << " " << cost2 << endl ;

            if ( cost >= cost2 ) lw2 = mid2a ;
            else hg2 = mid2a-1 ;
        }
        mid2 = ap[lw2] ;
        cost = ac[mid2] - 1ll * i * (X[mid2] - X[i]) - ac[i] + ac2[mid2] - 1ll * (R-mid-1) * (X[mid] - X[mid2]) - ac2[mid];
        //cout << i << " " << mid2 << " " <<mid << " cost " << cost << 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 1 ms 384 KB Output is correct
2 Incorrect 0 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 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 Incorrect 1 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 661 ms 4868 KB Output is correct
2 Correct 671 ms 4728 KB Output is correct
3 Execution timed out 1091 ms 26872 KB Time limit exceeded
4 Halted 0 ms 0 KB -