結果
| 問題 | No.286 Modulo Discount Store |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-01-30 18:17:25 |
| 言語 | Nim (2.2.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,304 bytes |
| 記録 | |
| コンパイル時間 | 568 ms |
| コンパイル使用メモリ | 43,520 KB |
| 最終ジャッジ日時 | 2025-12-08 18:37:49 |
| 合計ジャッジ時間 | 1,122 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
/home/judge/data/code/Main.nim(22, 25) Error: type mismatch Expression: newSeqWith[int](1 shl n + 1, 10000000000) [1] 1 shl n + 1: int [2] 10000000000: int Expected one of (first mismatch at [position]): [1] template newSeqWith(len: int; init: untyped): untyped extra generic param given
ソースコード
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]
for i in 0..<n:
if (x and ^i) > 0 : continue
dp[x or ^i] .min= dp[x] + 0.max(M[i] - total mod 1000)
dp[0] = 0
solve()
echo dp[^n-1]