結果

問題 No.50 おもちゃ箱
ユーザー むらためむらため
提出日時 2019-01-29 04:32:37
言語 Nim
(2.0.2)
結果
WA  
実行時間 -
コード長 2,159 bytes
コンパイル時間 2,582 ms
コンパイル使用メモリ 70,076 KB
実行使用メモリ 5,316 KB
最終ジャッジ日時 2023-09-14 03:12:23
合計ジャッジ時間 3,912 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 4 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 WA -
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 WA -
testcase_33 AC 2 ms
4,380 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 2 ms
4,376 KB
testcase_39 WA -
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sequtils,macros,algorithm,intsets
proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "<stdio.h>" .}
template `^`(n:int) : int = (1 shl n)
proc scan(): int =
  while true:
    let k = getchar_unlocked()
    if k < '0': return
    result = 10 * result + k.ord - '0'.ord

proc putchar_unlocked(c:char){. importc:"putchar_unlocked",header: "<stdio.h>" .}
proc printInt(a0:int32) =
  if a0 < 0 : putchar_unlocked('-')
  var a0 = a0.abs
  template div10(a:int32) : int32 = cast[int32]((0x1999999A * cast[int64](a)) shr 32)
  template put(n:int32) = putchar_unlocked("0123456789"[n])
  proc getPrintIntNimCode(n,maxA:static[int32]):string =
    result = "if a0 < " & $maxA & ":\n"
    for i in 1..n: result &= "  let a" & $i & " = a" & $(i-1) & ".div10\n"
    result &= "  put(a" & $n & ")\n"
    for i in n.countdown(1): result &= "  put(a" & $(i-1) & "-a" & $i & "*10)\n"
    result &= "  return"
  macro eval(s:static[string]): auto = parseStmt(s)
  eval(getPrintIntNimCode(0,10))
  eval(getPrintIntNimCode(1,100))
  eval(getPrintIntNimCode(2,1000))
  eval(getPrintIntNimCode(3,10000))
  eval(getPrintIntNimCode(4,100000))
  eval(getPrintIntNimCode(5,1000000))
  eval(getPrintIntNimCode(6,10000000))
  eval(getPrintIntNimCode(7,100000000))
  eval(getPrintIntNimCode(8,1000000000))
template printInt(n:int,c:char) =
  printInt(n.int32)
  putchar_unlocked(c)


let n = scan()
let A = newSeqWith(n,scan())#.sorted(cmp,Descending)
let m = scan()
let B = newSeqWith(m,scan())#.sorted(cmp,Descending)

var state = newSeq[int](^n)
for ni in 0..<(^n):
  for ia in 0..<n:
    if (ni and ^ia) != ^ia : continue
    state[ni] += A[ia] # 各状態の体積の和

proc getOKState(b:int): IntSet =
  result = initIntSet()
  for i,s in state:
    if b - s >= 0 : result.incl(i)

var ans = B[0].getOKState()
if ^n - 1 in ans: quit("1",0)
for i,b in B[1..^1]:
  var n_ans : IntSet
  n_ans.assign(ans)
  for x in b.getOKState().items:
    for y in ans.items:
      if (x and y) != 0 : continue
      n_ans.incl(x xor y)
  ans = n_ans
  if ^n - 1 in ans:
    printInt(i + 2,'\n')
    quit 0
putchar_unlocked('-')
putchar_unlocked('1')
putchar_unlocked('\n')
0