結果

問題 No.50 おもちゃ箱
ユーザー むらためむらため
提出日時 2017-08-15 15:21:14
言語 Nim
(2.0.2)
結果
AC  
実行時間 13 ms / 5,000 ms
コード長 1,093 bytes
コンパイル時間 3,590 ms
コンパイル使用メモリ 71,716 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-12 14:33:22
合計ジャッジ時間 5,118 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 4 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 13 ms
4,380 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 4 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 4 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 4 ms
4,376 KB
testcase_28 AC 4 ms
4,376 KB
testcase_29 AC 5 ms
4,376 KB
testcase_30 AC 3 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 4 ms
4,380 KB
testcase_33 AC 5 ms
4,380 KB
testcase_34 AC 7 ms
4,380 KB
testcase_35 AC 3 ms
4,384 KB
testcase_36 AC 4 ms
4,380 KB
testcase_37 AC 5 ms
4,376 KB
testcase_38 AC 3 ms
4,380 KB
testcase_39 AC 5 ms
4,376 KB
testcase_40 AC 5 ms
4,384 KB
testcase_41 AC 4 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 50) Warning: Use the new 'sugar' module instead; future is deprecated [Deprecated]
/home/judge/data/code/Main.nim(23, 57) Warning: Deprecated since v0.20, use 'toHashSet'; toSet is deprecated [Deprecated]
/home/judge/data/code/Main.nim(1, 50) Warning: imported and not used: 'future' [UnusedImport]
/home/judge/data/code/Main.nim(2, 13) Warning: imported and not used: 'tables' [UnusedImport]
/home/judge/data/code/Main.nim(1, 26) Warning: imported and not used: 'strscans' [UnusedImport]
/home/judge/data/code/Main.nim(1, 57) Warning: imported and not used: 'macros' [UnusedImport]

ソースコード

diff #

import sequtils,strutils,strscans,algorithm,math,future,macros
import sets,tables
template get*():string = stdin.readLine() #.strip()
template `max=`*(x,y:typed):void = x = max(x,y)
template optPow{`^`(2,n)}(n:int) : int = 1 shl n
template If*(ex:untyped):untyped = (if not(ex) : continue)
proc enumerate[T](arr:seq[T]): seq[tuple[i:int,val:T]] =
  result = @[]; for i,a in arr: result &= (i,a)

let
  N = get().parseInt()
  A = get().split().map(parseInt).sorted(cmp,Descending)
  M = get().parseInt()
  B = get().split().map(parseInt).sorted(cmp,Descending)

var state = newSeqWith(2^N,0)
for n in 0 ..< 2^N:
  for ia in 0 ..< N:
    If: (n and 2^ia) == 2^ia
    state[n] += A[ia] # 各状態の体積の和

proc getOKState(b:int): HashSet[int] =
  state.enumerate().filterIt(b-it.val >= 0).mapIt(it.i).toSet()

var ans = B[0].getOKState()
if 2^N-1 in ans:
  echo 1
  quit()

for i,b in B[1..^1]:
  var n_ans = ans
  for x in b.getOKState().items:
    for y in ans.items:
      If: (x and y) == 0
      n_ans.incl(x xor y)
  ans = n_ans
  if 2^N-1 in ans:
    echo i + 2
    quit()
echo -1
0