結果
問題 | No.50 おもちゃ箱 |
ユーザー |
![]() |
提出日時 | 2017-07-29 17:14:38 |
言語 | Nim (2.2.0) |
結果 |
AC
|
実行時間 | 91 ms / 5,000 ms |
コード長 | 1,011 bytes |
コンパイル時間 | 3,173 ms |
コンパイル使用メモリ | 65,808 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-30 01:53:25 |
合計ジャッジ時間 | 4,645 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 38 |
ソースコード
import sequtils,strutils,algorithm var N = stdin.readline.parseInt A = stdin.readline.split.map(parseInt) M = stdin.readline.parseInt B = stdin.readline.split.map(parseInt) cnt = M + 1 F : array[2048,bool] F[0] = true B.sort(system.cmp) B.reverse A.sort(system.cmp) A.reverse proc hantei(X : openarray[int]):bool = if X.len == 0: return false var flag = F for b in X: var flag2 = flag for i in 0..<(1 shl N): var n = b var f = true for k,a in A: if (i and (1 shl k)) > 0: n -= a if n < 0: f = false break if f == true: for j in 0..<(1 shl N): if flag[j] == true: flag2[j or i] = true flag = flag2 return flag[(1 shl N) - 1] while hantei(B): discard B.pop cnt -= 1 if cnt <= M: echo cnt else: echo -1