結果
問題 | No.286 Modulo Discount Store |
ユーザー |
|
提出日時 | 2023-02-07 14:16:58 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 6 ms / 2,000 ms |
コード長 | 769 bytes |
コンパイル時間 | 786 ms |
コンパイル使用メモリ | 83,604 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-05 10:57:58 |
合計ジャッジ時間 | 1,836 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
ソースコード
#include <iostream>#include <vector>#include <string>#include <set>#include <map>#include <algorithm>#include <numeric>#include <queue>#include <cassert>#include <cmath>#include <bitset>using namespace std;int n;int m[20];int p[40000];int dp[40000];void chmin(int &a, int b) {a = min(a, b);}int main() {cin >> n;for (int i = 0; i < n; i++) cin >> m[i];for (int s = 0; s < (1<<n); s++)for (int i = 0; i < n; i++)if (!(s&(1<<i)))p[s+(1<<i)] = p[s] + m[i];for (int s = 0; s < (1<<n); s++) dp[s] = 1000000000;dp[0] = 0;for (int s = 0; s < (1<<n); s++)for (int i = 0; i < n; i++)if (!(s&(1<<i)))chmin(dp[s+(1<<i)], dp[s] + max(0, m[i] - p[s]%1000));cout << dp[(1<<n)-1] << endl;}