結果
問題 |
No.286 Modulo Discount Store
|
ユーザー |
|
提出日時 | 2025-07-01 15:06:03 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 464 bytes |
コンパイル時間 | 1,605 ms |
コンパイル使用メモリ | 194,880 KB |
実行使用メモリ | 7,848 KB |
最終ジャッジ日時 | 2025-07-01 15:06:07 |
合計ジャッジ時間 | 3,445 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
ソースコード
#include<bits/stdc++.h> using namespace std; int N,M[15]; int dp[1<<15]; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cin>>N; for(int i=0;i<N;i++)cin>>M[i]; for(int i=1;i<1<<N;i++)dp[i]=2e9; for(int i=0;i<1<<N;i++){ int sm=0; for(int j=0;j<N;j++)if(i>>j&1)sm+=M[j]; sm%=1000; for(int j=0;j<N;j++)if(!(i>>j&1)){ dp[i|1<<j]=min(dp[i|1<<j],dp[i]+max(M[j]-sm,0)); } } cout<<dp[(1<<N)-1]<<'\n'; return 0; }