結果

問題 No.2844 Birthday Party Decoration
ユーザー E49869826E49869826
提出日時 2024-08-24 00:27:11
言語 Nim
(2.0.2)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 3,152 bytes
コンパイル時間 4,461 ms
コンパイル使用メモリ 98,792 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-08-24 00:27:16
合計ジャッジ時間 4,694 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 5 ms
6,944 KB
testcase_02 AC 5 ms
6,944 KB
testcase_03 AC 6 ms
6,940 KB
testcase_04 AC 6 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
check is on
optimized for speed

ソースコード

diff #

# Please use Nim-ACL
import macros; macro ImportExpand(s:untyped):untyped = parseStmt(staticExec("echo " & $s[2] & " | base64 -d | xzcat"))
# const OPTIMIZE_SIZE = true
ImportExpand "e_lib/templates/prelude.nim" <=== "/Td6WFoAAATm1rRGAgAhARwAAAAQz1jM4AG2AM1dADuaCNQtYnSg9EGWFdHzgJ4ZEZPA2A4GC71uJBE1Q5DCmJ6ip+BHSeOQAxKLZNxc8uvrgoLZaEvkfszH6ztT7Cqw+jwCLVNdnRZ/o9+gCa9AuZUCsQ4v1tT4NKMRrzE/FkvGFODweh31CM40Dbck8Q+4kjr0K6GP8du1rARBMqUymwor117W4ZKywO7//4q3Bv0h2J6NQM80thqxqFGl8ClE2WagETBiKou1DlpVvHO5fv1Mjn1l8RNWhRCFV2rSKTSfdGoS/coONb2/AAAAAAAAUjvPkh7B5A8AAekBtwMAAF1/nU2xxGf7AgAAAAAEWVo="
ImportExpand "e_lib/templates/header.nim" <=== "/Td6WFoAAATm1rRGAgAhARwAAAAQz1jM4A03BGddADuaCNQtYnSg9EGWFdHzgJ4ZEZPA2A4GC71uJBE1Q5DCmJ6f3yWtfXn3fnQS4aijNu6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UVI3l72/v9zOfj22rAvDaUJgSqDh1RHN8cCXAJwr3/YY4Yx75WsRUkWqygzX4cg+uc86G6PZ0UZaW3oUMhpAJcMHVchreNrI9sE/w979ZRapbIO7liNOGCKGlL1AFgOhgd9Lx/5FbUV/IuDdjMxKD/nvskiXC8cV1Hh7wNdokaGSDNIqKcr4LDNOsqtfMRNzh/PKFZ8jrRO6oyQ8qcGJauGS/S93wuwoFO3GxyI2PeesESKO6PFp0iIb8o8MOGIyPXmeuZ/3W/OpRESdCS0Gcqcao9dLIFGoQCBqMM+iudeS1ZtGdveWfgtHG2fy4ho0IPt9cSwiC2FhwFVqD4rc0mzXCSypw90fONMkXZe/8eUAABFDYk4U9GKwgABgwm4GgAACZAWn7HEZ/sCAAAAAARZWg=="

# no echo
proc solve(N,X:int;c:seq[int]):void =
  var c0 = newSeqUninitialized[int](N)
  var c1 = newSeqUninitialized[int](N)
  for i in 0..<N:
    if X.testBit(c[i]):
      c0[i] = X
      c1[i] = X
      continue
    let te1 = X.clearMasked(0..c[i])
    if te1 == 0: c0[i] = -1
    else: c0[i] = te1-1
    c1[i] = te1.dup(setBit(c[i]))
  let te2 = (0..<N).toSeq.sortedbyIt(c1[it])
  var res = (c1[te2[N-1]]-X) shl 1
  var re0 = X
  block bl1:
    for i in 0..<N-1:
      if c0[te2[N-1-i]] == -1: break bl1
      re0.applyMin(c0[te2[N-1-i]])
      res.applyMin(((c1[te2[N-2-i]]-X) shl 1) + ((X-re0) shl 1))
    if c0[te2[0]] == -1: break bl1
    re0.applyMin(c0[te2[0]])
    res.applyMin((X-re0) shl 1)
  stdout.writeLine(res)
  return

proc main():void =
  # Failed to predict input format
  let T = nextInt()
  for i in 0..<T:
    let N, X = nextInt()
    let c = newSeqWith(N,nextInt())
    solve(N,X,c)
  return

main()
0