Submission #113026

# Submission time Handle Problem Language Result Execution time Memory
113026 2019-05-23T07:25:16 Z CaroLinda Rice Hub (IOI11_ricehub) C++14
100 / 100
19 ms 2812 KB
#include <bits/stdc++.h>
#include "ricehub.h"
 
#define lp(i,a,b) for(int i = a ; i < b ; i++)
#define ll long long
#define pii pair<int,int>
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
 
const int inf = 1e9 + 10 ;
const int MAXN = 1e5 + 10 ;
 
using namespace std ;
 
int l , r , x[MAXN] ;
ll b , pref[MAXN] , suf[MAXN] ;
 
int m(int a , int b)
{ return (a+b)/2 ; }
 
ll d(int a , int b  )
{ return abs( x[a] - x[b] ) ; }
 
ll c1(int a , int b)
{ return pref[b] - pref[a] - (b-a) * d(a,1) ; }
 
ll c2(int a , int b)
{ return suf[a] - suf[b] - (b-a) * d(b,r) ; }
 
bool test(int tam)
{
 
  int ini = 1 , fim = tam ;
 
  while( fim <= r )
  {
    int now = m(ini,fim) ;
    if( ( c2( ini , now ) + c1( now , fim ) ) <= b ) 
      return true ;
    ini ++ , fim++ ;
  }
  
  return false ;
 
}
 
int besthub(int R , int L , int X[] , ll B )
{
  b = B , r = R , l = L ;
  lp(i,1,r+1) x[i] = X[i-1] ;
 
  sort( x+1 , x+r+1 ) ;
 
  lp(i,1,r+1) pref[i] = pref[i-1] + d(i,1) ;
 
  for(int i = r ; i > 0 ; i-- ) suf[i] = suf[i+1] + d(i,r) ;
 
  int ini = 1 , fim = r , best = 1;
 
  while( ini <= fim )
  {
    if( test( m(ini,fim) ) )
    {
      best = m(ini,fim) ;
      ini = m(ini,fim) + 1 ;
    }
 
    else fim = m(ini,fim) - 1;
 
  }
 
  return best ;
 
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 380 KB Output is correct
16 Correct 2 ms 284 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 768 KB Output is correct
2 Correct 5 ms 768 KB Output is correct
3 Correct 17 ms 2688 KB Output is correct
4 Correct 17 ms 2812 KB Output is correct
5 Correct 10 ms 1536 KB Output is correct
6 Correct 10 ms 1536 KB Output is correct
7 Correct 15 ms 2688 KB Output is correct
8 Correct 15 ms 2688 KB Output is correct
9 Correct 9 ms 1536 KB Output is correct
10 Correct 10 ms 1536 KB Output is correct
11 Correct 19 ms 2688 KB Output is correct
12 Correct 18 ms 2688 KB Output is correct
13 Correct 11 ms 1536 KB Output is correct
14 Correct 11 ms 1536 KB Output is correct
15 Correct 14 ms 2048 KB Output is correct
16 Correct 14 ms 2096 KB Output is correct
17 Correct 17 ms 2424 KB Output is correct
18 Correct 16 ms 2432 KB Output is correct
19 Correct 17 ms 2560 KB Output is correct
20 Correct 17 ms 2552 KB Output is correct