제출 #1077447

#제출 시각아이디문제언어결과실행 시간메모리
1077447Trumling선물상자 (IOI15_boxes)C++14
0 / 100
2077 ms348 KiB
#include "boxes.h"
#include<bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define pb push_back
#define INF 99999999999999
#define all(x) x.begin(),x.end()
typedef long long ll;

long long delivery(int N, int K, int L, int p[]) {
ll n=N;
vector<ll>v;
    for(int i=0;i<n;i++)
        v.pb(i);

    ll ans=INF;
    do
    {

    ll curr=min(p[v[0]],L-p[v[0]]);
    ll count=K-1;
    ll pos=v[0];
    for(int i=0;i<n-1;i++)
    {
        
        if(count==0)
        {
            curr+=min(p[v[i]],L-p[v[i]]);
            count=K;
            pos=0;
        }
        count--;
        if(abs(p[pos]-p[v[i+1]])>min(p[v[i+1]],L-p[v[i+1]]) + min(p[pos],L-p[pos]))
        {
            curr+=min(p[v[i+1]],L-p[v[i+1]]) + min(p[pos],L-p[pos]);
            pos=v[i+1];
            count=K-1;
        }
        else
        curr+=abs(p[pos]-p[v[i+1]]); 
    }

    curr+=min(p[pos] , L - p[pos]);
    ans=min(ans,curr);
    
    } while (next_permutation(all(v)));
    
    return ans;
}
#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...