結果
| 問題 | No.15 カタログショッピング | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2019-01-31 20:38:02 | 
| 言語 | Nim (2.2.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,050 bytes | 
| コンパイル時間 | 3,690 ms | 
| コンパイル使用メモリ | 72,068 KB | 
| 実行使用メモリ | 19,200 KB | 
| 最終ジャッジ日時 | 2024-07-01 11:14:39 | 
| 合計ジャッジ時間 | 4,804 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 6 WA * 4 | 
ソースコード
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
            
            
            
        