結果

問題 No.50 おもちゃ箱
ユーザー むらためむらため
提出日時 2019-01-29 04:43:04
言語 Nim
(2.0.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,175 bytes
コンパイル時間 3,201 ms
コンパイル使用メモリ 70,376 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-14 03:12:28
合計ジャッジ時間 4,731 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 WA -
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 4 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 WA -
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 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,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 3 ms
4,376 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 3 ms
4,376 KB
testcase_41 AC 2 ms
4,380 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())
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): seq[bool] =
  result = newSeq[bool](^n)
  for i,s in state:
    if b - s >= 0 : result[i] = true

let m = scan()
let B = newSeqWith(m,scan()).sorted(cmp,Descending)
var ans = B[0].getOKState()
if ans[^n - 1]: quit("1",0)
for i,b in B[1..^1]:
  var pre = ans
  var bAns = b.getOKState()
  for x in 0..<(^n):
    if not bAns[x] : continue
    for y in 0..<(^n):
      if not pre[y] : continue
      if (x and y) != 0 : continue
      ans[x xor y] = true
  if ans[^n - 1]:
    printInt(i + 2,'\n')
    quit 0
putchar_unlocked('-')
putchar_unlocked('1')
putchar_unlocked('\n')
0