結果
| 問題 | No.286 Modulo Discount Store |
| コンテスト | |
| ユーザー |
37kt_
|
| 提出日時 | 2015-10-17 18:07:32 |
| 言語 | C++11 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 52 ms / 2,000 ms |
| コード長 | 605 bytes |
| 記録 | |
| コンパイル時間 | 1,488 ms |
| コンパイル使用メモリ | 175,796 KB |
| 実行使用メモリ | 7,972 KB |
| 最終ジャッジ日時 | 2026-04-03 08:35:13 |
| 合計ジャッジ時間 | 2,239 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 40 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define BIT(i) (1 << (i))
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define CHMIN(a, b) a = min(a, b)
const int INF = 1 << 28;
int n;
int a[15];
int dp[1 << 15];
int main()
{
cin >> n;
REP(i, n) cin >> a[i];
fill_n(dp, 1 << 15, INF);
dp[0] = 0;
REP(k, n) REP(bit, BIT(n)){
if (dp[bit] == INF) continue;
int s = 0;
REP(i, n) if (bit & BIT(i)) s += a[i];
s %= 1000;
REP(i, n){
if (bit & BIT(i)) continue;
int t = max(0, a[i] - s);
CHMIN(dp[bit | BIT(i)], dp[bit] + t);
}
}
cout << dp[BIT(n) - 1] << endl;
}
37kt_