結果
問題 |
No.286 Modulo Discount Store
|
ユーザー |
|
提出日時 | 2020-02-12 07:25:53 |
言語 | Nim (2.2.0) |
結果 |
AC
|
実行時間 | 6 ms / 2,000 ms |
コード長 | 628 bytes |
コンパイル時間 | 3,070 ms |
コンパイル使用メモリ | 67,132 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-02 09:19:54 |
合計ジャッジ時間 | 4,158 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
ソースコード
import strutils, sequtils, math, algorithm proc solve() = var N = stdin.readLine.parseInt M = mapIt(1..N, stdin.readLine.parseInt) dp: array[2^16, int] const INF = 10000 * 15 dp.fill(INF) dp[0] = 0 for S in 0..<1 shl N: var m_sum = 0 for i in 0..<N: if ((S shr i) and 1) == 1: m_sum += M[i] let d = m_sum mod 1000 for i in 0..<N: if ((S shr i) and 1) == 0: dp[S or (1 shl i)] = min(dp[S or (1 shl i)], dp[S] + max(0, M[i] - d)) echo dp[2^N - 1] when is_main_module: solve()