結果

問題 No.15 カタログショッピング
ユーザー むらためむらため
提出日時 2019-01-31 20:38:02
言語 Nim
(2.0.2)
結果
WA  
実行時間 -
コード長 1,050 bytes
コンパイル時間 3,469 ms
コンパイル使用メモリ 71,376 KB
実行使用メモリ 20,156 KB
最終ジャッジ日時 2023-09-14 03:20:14
合計ジャッジ時間 5,066 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 176 ms
19,004 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sequtils,algorithm,tables,strutils
template `^`(n:int) : int = (1 shl n)

proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "<stdio.h>" .}
proc scan(): int =
  while true:
    let k = getchar_unlocked()
    if k < '0': return
    result = 10 * result + k.ord - '0'.ord

proc build(P:seq[int],carry:int = 1) : Table[int,seq[string]] =
  result = initTable[int,seq[string]]()
  for x in 0 ..< ^P.len:
    var total = 0
    var pair = ""
    for j in 0..<P.len:
      if (^j and x) > 0 :
        total += P[j]
        pair &= $(j+carry) & " "
    if total notin result: result[total] = @[]
    result[total] &= pair

let n = scan()
let s = scan()
let P = newSeqWith(n,scan())
if n == 1: quit "1",0
let P1 = P[0..<n div 2]
let P2 = P[(n div 2) ..< n]
let I1 = P1.build(1)
let I2 = P2.build(1+(n div 2))
var answers = newSeq[string]()
for i2,strs in I2:
  if s - i2 notin I1 : continue
  for s1 in I1[s-i2]:
    for s2 in strs:
      answers &= s1 & s2
answers = answers.mapIt(it.strip()).sorted(cmp)
for ans in answers:
  echo ans
0