結果
| 問題 | No.15 カタログショッピング |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-01-31 20:44:33 |
| 言語 | Nim (2.2.0) |
| 結果 |
AC
|
| 実行時間 | 73 ms / 5,000 ms |
| コード長 | 1,190 bytes |
| コンパイル時間 | 3,805 ms |
| コンパイル使用メモリ | 73,540 KB |
| 実行使用メモリ | 22,708 KB |
| 最終ジャッジ日時 | 2024-07-01 11:14:33 |
| 合計ジャッジ時間 | 4,611 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 |
ソースコード
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[seq[int]]] =
result = initTable[int,seq[seq[int]]]()
for x in 0 ..< ^P.len:
var total = 0
var pair = newSeq[int]()
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[seq[int]]()
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).sorted(proc(x,y:seq[int]):int =
for i in 0..<min(x.len,y.len):
if x[i] != y[i] : return x[i] - y[i]
return x.len - y.len
)
for ans in answers:
echo ans.mapIt($it).join(" ")