제출 #1242335

#제출 시각아이디문제언어결과실행 시간메모리
1242335tkm_algorithms선물상자 (IOI15_boxes)C++20
0 / 100
0 ms328 KiB
/**
*    In the name of Allah
*    We are nothing and you're everything
*    Ya Muhammad!
**/
#include <bits/stdc++.h>
#include "boxes.h"
 
using namespace std;
using ll = long long;
using ull = uint64_t;
 
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
//#define int long long

const char nl = '\n';

long long delivery(int n, int k, int L, int p[]) {
	ll res = 0, pos = 0;
	vector<ll> l;
	for (int i = 0; i < n; ++i) {
		if (p[i]>(L+1)/2)break;
		if (i+1 <= k)l.push_back(p[i]*2);
		else l.push_back(l[sz(l)-k-1]+p[i]*2);
		res = l.back();
		pos = i+1;
	}
	
	ll back = 0;
	vector<ll> r;
	for (int i = pos; i < n; ++i) {
		if (sz(r) < k)r.push_back((L-p[i])*2);
		else r.push_back(r[sz(r)-k]+(L-p[i])*2);
		back = r.back();
	}
	
	res += back;
	
	for (int i = 0; i < sz(l); ++i) {
		for (int j = sz(r)-1; j >= 0; --j) {	
			if (sz(l)-i+sz(r)-j > k)continue;
			res = min(res, (i>0?l[i-1]:0ll)+L+(j-1>=0?r[j-1]:0ll));
		}
	}
    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...