Submission #727275

#TimeUsernameProblemLanguageResultExecution timeMemory
727275Vu_CG_CoderBoxes with souvenirs (IOI15_boxes)C++14
100 / 100
548 ms254804 KiB
/* [Author : Hoang Duy Vu] - THPT Chuyen Nguyen Du    */
//#pragma GCC optimize(" unroll-loops")
//#pragma gcc optimize("Ofast")
//#pragma GCC optimization("Ofast")
//#pragma optimize(Ofast)
#include "boxes.h"
#include <bits/stdc++.h>
#define All(x) (x).begin(),(x).end()
#define ll long long
#define C make_pair
#define fi first
#define se second
#define two second.first
#define thr second.second
#define TASK "txt"
using namespace std;
template<typename T> bool maximize(T &res, const T &val) {
    if (res < val) { res = val; return true; } return false; }
template<typename T> bool minimize(T &res, const T &val) {
    if (res > val) { res = val; return true; } return false; }

typedef pair<int,int> ii;
typedef pair<int,ii> iii;
const int LOG = 20;
const int INF = 1e9 + 7;
const ll LNF = 1e18 + 7;
const int mod = 1e9 + 7;
const int N = 1e7 + 100;

ll delivery(int n , int k , int l , int p[])
{
    vector <ll> pre , suff;
    pre.assign(n,LNF);
    suff.assign(n,LNF);

    for (int i = 0 , j = n - 1 ; i < n ; i++,j--)
    if (i < k)
    {
        pre[i] = 1ll*min(p[0],l - p[0]) + min(p[i],l - p[i]) + 1ll*p[i] - p[0];
        suff[j] = 1ll*min(p[n - 1],l - p[n - 1]) + 1ll*min(p[j],l - p[j]) + 1ll*p[n - 1] - p[j];
    }
    else
    {
        pre[i] = pre[i - k] + min(p[i - k + 1],l - p[i - k + 1]) + min(p[i],l - p[i]) + p[i] - p[i - k + 1];
        suff[j] = suff[j + k] + min(p[j + k - 1],l - p[j + k - 1]) + min(p[j],l - p[j]) + p[j + k - 1] - p[j];
    }

    ll res = pre[n - 1];
    minimize(res,suff[0]);

    for (int i = 1 ; i < n ; i++) minimize(res,pre[i - 1] + suff[i]);

    return res;
}

// int main()
// {
//     ios_base::sync_with_stdio(0);
//     cin.tie(NULL); cout.tie(NULL);
//     if(fopen(TASK".inp", "r")){
//     freopen(TASK".inp","r",stdin);
//     freopen(TASK".out","w",stdout);
//     }

//     int n , k , l;
//     cin >> n >> k >> l;
//     vector <int> x;
//     x.assign(n,0);
//     for (int &v : x) cin >> v;

//     cout << delivery(n,k,l,x);
//     return 0;
// }

#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...