이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {
cerr<<vars<<" = ";
string delim="";
(...,(cerr<<delim<<values,delim=", "));
cerr<<"\n";
}
#else
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {}
#endif
#define pb push_back
#define sz(x) (int)(x.size())
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> inline void maxa(T& a,T b){a=max(a,b);}
template<typename T> inline void mina(T& a,T b){a=min(a,b);}
// ll delivery(int N, int K, int L, int positions[]){
// ll ans=0;
// vector<int> pos;
// for(int i=0;i<N;i++){
// if(positions[i])
// pos.pb(positions[i]);
// }
// int n=sz(pos);
// vector<ll> pref(n),suff(n);
// for(int i=0;i<n;i++){
// if(i<K){
// pref[i]=min(2*pos[i],L);
// } else{
// pref[i]=pref[i/K*K-1]+min(2*pos[i],L);
// }
// }
// for(int i=n-1;i>=0;i--){
// if(n-i-1<K){
// suff[i]=min(2*(L-pos[i]),L);
// } else{
// suff[i]=suff[n-1-(n-i-1)/K*K+1]+min(2*(L-pos[i]),L);
// }
// }
// ans=min(pref[n-1],suff[0]);
// for(int i=0;i<n-1;i++)
// mina(ans,pref[i]+suff[i+1]);
// return ans;
// }
ll dp[12][12][1<<11],n,k,l,pos[15];
ll make(int at,int rem,int mask){
if(~dp[at][rem][mask])
return dp[at][rem][mask];
ll res=1e18;
if(at!=n)
res=make(n,k,mask)+min(l-pos[at],pos[at]);
if(pos[at]){
if(rem==1)
return dp[at][rem][mask]=res;
for(int i=0;i<n;i++){
if(!(mask&(1<<i))){
mina(res,make(i,rem-1,mask|(1<<i))+min(abs(pos[at]-pos[i]),pos[at]+pos[i]));
}
}
} else{
for(int i=0;i<n;i++){
if(!(mask&(1<<i))){
mina(res,make(i,k,mask|(1<<i))+min(pos[i],l-pos[i]));
}
}
}
// cout<<at<<" "<<rem<<" ";
// for(int i=0;i<n;i++){
// if(mask&(1<<i))
// cout<<1;
// else
// cout<<0;
// }
// cout<<" "<<res<<"\n";
return dp[at][rem][mask]=(res==1e18?0:res);
}
ll delivery(int N,int K,int L, int positions[]){
n=N; k=K; l=L;
for(int i=0;i<n;i++)
pos[i]=positions[i];
memset(dp,-1,sizeof(dp));
return make(n,k,0);
}
컴파일 시 표준 에러 (stderr) 메시지
boxes.cpp: In function 'll make(int, int, int)':
boxes.cpp:64:18: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
64 | res=make(n,k,mask)+min(l-pos[at],pos[at]);
| ^
boxes.cpp:64:20: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
64 | res=make(n,k,mask)+min(l-pos[at],pos[at]);
| ^
boxes.cpp:76:33: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
76 | mina(res,make(i,k,mask|(1<<i))+min(pos[i],l-pos[i]));
| ^
boxes.cpp:88:31: warning: conversion from 'll' {aka 'long long int'} to 'double' may change value [-Wconversion]
88 | return dp[at][rem][mask]=(res==1e18?0:res);
| ^~~
boxes.cpp: In function 'll delivery(int, int, int, int*)':
boxes.cpp:96:17: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
96 | return make(n,k,0);
| ^
boxes.cpp:96:19: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
96 | return make(n,k,0);
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |