# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
389132 | PedroBigMan | 선물상자 (IOI15_boxes) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "boxes.h"
/*
Author of all code: Pedro BIGMAN Dias
Last edit: 15/02/2021
*/
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <list>
#include <iomanip>
#include <stdlib.h>
#include <time.h>
#include <cstring>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define REP(i,a,b) for(ll i=(ll) a; i<(ll) b; i++)
#define pb push_back
#define mp make_pair
#define pl pair<ll,ll>
#define ff first
#define ss second
#define whole(x) x.begin(),x.end()
#define DEBUG(i) cout<<"Pedro Is The Master "<<i<<endl
#define INF 1000000000000000000LL
#define EPS 0.00000001
#define pi 3.14159
ll mod=1000000007LL;
template<class A=ll>
void Out(vector<A> a) {REP(i,0,a.size()) {cout<<a[i]<<" ";} cout<<endl;}
template<class A=ll>
void In(vector<A> &a, ll N) {A cur; REP(i,0,N) {cin>>cur; a.pb(cur);}}
ll delivery(int n, int k, int l, int pos[])
{
ll N = (ll) n; ll K = (ll) k; ll L = (ll) l; vector<ll> p; REP(i,0,N) {p.pb((ll) pos[i]);}
vector<ll> h1,h2; ll newN=0LL;
REP(i,0,N)
{
if(p[i]==0) {continue;}
newN++;
if(p[i]<=(L-1LL)/2LL) {h1.pb(p[i]);}
else if(p[i]>=(L+2LL)/2LL) {h2.pb(L-p[i]);}
}
N=newN;
ll N1=h1.size(); ll N2 = h2.size(); sort(whole(h1)); sort(whole(h2));
vector<ll> dp1,dp2; dp1.pb(0LL); dp2.pb(0LL);
REP(i,0,N1)
{
if(i<K) {dp1.pb(2LL*h1[i]);}
else {dp1.pb(2LL*h1[i]+dp1[i-K+1]);}
}
REP(i,0,N2)
{
if(i<K) {dp2.pb(2LL*h2[i]);}
else {dp2.pb(2LL*h2[i]+dp2[i-K+1]);}
}
while(dp1.size()<=N) {dp1.pb(INF);} while(dp2.size()<=N) {dp2.pb(INF);}
vector<ll> minyet;
vector<ll> y;
REP(i,0,N+1)
{
y.pb(K*dp2[i]-i*L);
if(i<K) {minyet.pb(y[i]);} else {minyet.pb(min(y[i],minyet[i-K]));}
}
vector<ll> f;
REP(S,0,N+1)
{
f.pb(min((S*L+minyet[S])/K),L*((S-K+1LL)/K));
}
ll ans = INF;
REP(i,0,N+1)
{
ans=min(ans,f[i]+dp1[N-i]);
}
return ans;
}