結果

問題 No.286 Modulo Discount Store
ユーザー Lay_ec
提出日時 2015-10-09 22:50:38
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 266 ms / 2,000 ms
コード長 1,167 bytes
コンパイル時間 711 ms
コンパイル使用メモリ 85,884 KB
実行使用メモリ 260,352 KB
最終ジャッジ日時 2024-07-20 04:23:39
合計ジャッジ時間 2,909 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <sstream>
#include <map>
#include <queue>
#include <stack>
using namespace std;
long long inf=1000000000;
int main()
{
int n;
cin>>n;
vector<long long> p(n);
for(int i=0;i<n;i++) cin>>p[i];
vector<vector<long long> > dp(1<<n,vector<long long>(1000,inf));
dp[0][0]=0;
for(int bit=0;bit<(1<<n);bit++){
for(long long i=0;i<1000;i++){
if(dp[bit][i]==inf) continue;
for(int j=0;j<n;j++){
if(bit&(1<<j)) continue;
int next=bit|(1<<j);
//printf("(%lld,%lld)=%lld ->",bit,i,dp[bit][i]);
dp[next][(i+p[j])%1000]=min(dp[next][(i+p[j])%1000],dp[bit][i]+max(0LL,p[j]-i));
//printf("(%lld,%lld)=%lld\n",next,(i+p[j])%1000,dp[next][(i+p[j])%1000]);
}
}
}
long long res=dp[(1<<n)-1][0];
for(int i=1;i<1000;i++) res=min(res,dp[(1<<n)-1][i]);
cout<<res<<endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0