結果
問題 |
No.286 Modulo Discount Store
|
ユーザー |
![]() |
提出日時 | 2019-06-06 15:35:04 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 6 ms / 2,000 ms |
コード長 | 783 bytes |
コンパイル時間 | 1,585 ms |
コンパイル使用メモリ | 167,324 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-25 09:51:54 |
合計ジャッジ時間 | 2,798 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
ソースコード
#include<bits/stdc++.h> #define debug(x) cerr << #x << ": " << x << '\n' #define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n' using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<ll> vll; const ll INF = INT_MAX; const ll MOD = 1e9+7; int main(){ cin.tie(0); ios::sync_with_stdio(false); ll N;cin>>N; ll M[N];for(ll i=0;i<N;i++)cin>>M[i]; ll dp[1<<N]={}; fill(dp,dp+(1<<N),INF); dp[0]=0; for(ll S=0;S<1<<N;S++){ ll dis=0; for(ll i=0;i<N;i++)if((S>>i)&1){ dis = (dis+M[i])%1000; } for(ll i=0;i<N;i++)if(!((S>>i)&1)){ dp[S|(1<<i)] = min(dp[S|(1<<i)],dp[S]+max(0ll,M[i]-dis)); } } cout<<dp[(1<<N)-1]<<endl; return 0; }