Submission #1272103

#TimeUsernameProblemLanguageResultExecution timeMemory
1272103thunoproBoxes with souvenirs (IOI15_boxes)C++20
0 / 100
1 ms572 KiB
#include "boxes.h"
#include<bits/stdc++.h>
using namespace std ; 
#define maxn 200009
#define ll long long 
#define pb push_back 
#define fi first 
#define se second 
#define left id<<1
#define right id<<1|1 
#define re exit(0); 
#define _lower(x) lower_bound(v.begin(),v.end(),x)-v.begin()+1 
#define TIME ( 1.0*clock() / CLOCKS_PER_SEC )
const int mod = 1e9+7 ;
const int INF = 1e9 ; 

typedef vector<int> vi ; 
typedef pair<int,int> pii ; 
typedef vector<pii> vii ; 

template < typename T > void chkmin ( T &a , T b ) { if ( a > b ) a = b ; } 
template < typename T > void chkmax ( T &a , T b ) { if ( a < b ) a = b ; } 

void add ( int &a , int b ) 
{
    a += b ; 
    if ( a >= mod ) a -= mod ; 
    if ( a < 0 ) a += mod ; 
}

int n , k , L ;
int p [maxn] ; 
ll dp [maxn] ; 

bool in_right ( int pos ) 
{
    return ( pos >= (L+1)/2 ) ; 
}
long long delivery(int _N, int _K, int _L, int _p[]) {
    n = _N , k = _K , L = _L ;
    for ( int i = 1 ; i <= n ; i ++ ) p [i] = _p [i-1] ;
    int pos = -1 ;  
    for ( int i = 1 ; i <= n ; i ++ )
    {
        if ( in_right (p[i]) ) 
        {
            pos = i ; 
            break ; 
        }
        dp [i] = dp [max(0,i-k)] + p [i] ; 
    }  
    for ( int i = n ; in_right (i) ; i -- ) dp [i] = dp [min(n+1,i+k)] + L - p [i] ;

    ll res = 1e18 ; 
    for ( int i = 1 ; i <= n ; i ++ ) 
    {
        if ( i + k - 1 < pos ) continue ; 
        if ( i + k - 1 > n || i >= pos ) break ;
        res = min (res,2*dp[i-1]+2*dp[i+k]+L) ;  
    }
    return res;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...