Submission #1272113

#TimeUsernameProblemLanguageResultExecution timeMemory
1272113thunoproBoxes with souvenirs (IOI15_boxes)C++20
100 / 100
370 ms274508 KiB
#include "boxes.h"
#include<bits/stdc++.h>
using namespace std ; 
#define maxn 10000009
#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 dp1 [maxn] , dp2 [maxn] ; 
int stk1 [maxn] , stk2 [maxn] ; 

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 num1 = 0 , num2 = 0 ;
    for ( int i = 1 ; i <= n ; i ++ ) 
    {
        if ( p [i] <= L / 2 ) stk1 [++num1] = p [i] ; 
        else stk2 [++num2] = L - p [i] ; 
    }    
    for ( int i = 1 ; i <= num2 / 2  ; i ++ ) swap (stk2[i],stk2[num2-i+1]) ;
    
    for ( int i = 1 ; i <= n ; i ++ ) dp1 [i] = dp2 [i] = 1e18 ; 
    for ( int i = 1 ; i <= num1 ; i ++ ) chkmin (dp1[i],dp1[max(i-k,0)]+stk1[i]) ; 
    for ( int i = 1 ; i <= num2 ; i ++ ) chkmin (dp2[i],dp2[max(i-k,0)]+stk2[i]) ; 

    ll res = (dp1[num1]+dp2[num2])*2 ; 
    for ( int i = max(num1-k,0) ; i <= num1 ; i ++ ) 
    {
        chkmin (res,(dp1[i]+dp2[max(0,n-k-i)])*2 + 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...