結果
問題 |
No.286 Modulo Discount Store
|
ユーザー |
|
提出日時 | 2019-01-30 18:18:08 |
言語 | Nim (2.2.0) |
結果 |
AC
|
実行時間 | 7 ms / 2,000 ms |
コード長 | 1,322 bytes |
コンパイル時間 | 2,505 ms |
コンパイル使用メモリ | 62,284 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-01 11:13:09 |
合計ジャッジ時間 | 3,595 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
ソースコード
import sequtils,algorithm # import ,math,tables # import sets,intsets,queues,heapqueue,bitops,strutils # import strutils,strformat,sugar,macros # template stopwatch(body) = (let t1 = cpuTime();body;echo "TIME:",(cpuTime() - t1) * 1000,"ms") template times*(n:int,body) = (for _ in 0..<n: body) template `max=`*(x,y) = x = max(x,y) template `min=`*(x,y) = x = min(x,y) template `^`(n:int) : int = (1 shl n) proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "<stdio.h>" .} proc scan(): int = while true: let k = getchar_unlocked() if k < '0': return result = 10 * result + k.ord - '0'.ord let n = scan() let M = newSeqWith(n,scan()).sorted(cmp) const INF = 1e10.int var ans = INF var dp = newSeqWith[int](^n + 1,INF) # proc solve(s,total,buyTotal:int) = # if s == ^n - 1: # ans .min= total # return # if dp[s] <= total : return # dp[s] = total # for x in 0..<n: # if (^x and s ) > 0 : continue # solve(s or ^x,total + (M[x] - (buyTotal mod 1000)).max(0),buyTotal+M[x]) # solve(0,0,0) proc solve() = for x in 0..<(^n - 1): var total = 0 for i in 0..<n: if (x and ^i) > 0 : total += M[i] total = total mod 1000 for i in 0..<n: if (x and ^i) > 0 : continue dp[x or ^i] .min= dp[x] + 0.max(M[i] - total) dp[0] = 0 solve() echo dp[^n-1]