結果
| 問題 |
No.15 カタログショッピング
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-05-26 14:45:12 |
| 言語 | Go (1.23.4) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,513 bytes |
| コンパイル時間 | 15,472 ms |
| コンパイル使用メモリ | 227,508 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-11 05:10:48 |
| 合計ジャッジ時間 | 22,604 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 6 WA * 4 |
ソースコード
package main
import (
"fmt"
"sort"
"strconv"
"strings"
)
type priceAndItem struct {
p int
i int32
}
type priceAndItemS []priceAndItem
func (p priceAndItemS) Len() int {
return len(p)
}
func (p priceAndItemS) Swap(i, j int) {
p[i], p[j] = p[j], p[i]
}
func (p priceAndItemS) Less(i, j int) bool {
return p[i].p < p[j].p
}
func conv(l int32) string {
s := make([]string, 0, 32)
for i := uint(0); i < 32; i++ {
if (l & (1 << i)) == 0 {
continue
}
s = append(s, strconv.Itoa(int(i+1)))
}
return strings.Join(s, " ")
}
func price(P []int, l int32) int {
p := 0
for i := uint(0); i < uint(len(P)); i++ {
if (l & (1 << i)) == 0 {
continue
}
p += P[i]
}
return p
}
func main() {
var N, S int
fmt.Scan(&N, &S)
P := make([]int, N)
for i := range P {
fmt.Scan(&P[i])
}
fh := make(priceAndItemS, 0, 1<<uint(N/2))
for i := int32(0); i < 1<<uint(N/2); i++ {
fh = append(fh, priceAndItem{
p: price(P, i),
i: i,
})
}
var tmp uint
if N%2 == 0 {
tmp = uint(N / 2)
} else {
tmp = uint(N/2 + 1)
}
lh := make(priceAndItemS, 0, 1<<tmp)
for i := int32(0); i < 1<<tmp; i++ {
item := i << uint(N/2)
lh = append(lh, priceAndItem{
p: price(P, item),
i: item,
})
}
sort.Sort(lh)
var res []int32
for _, f := range fh {
for _, l := range lh {
if f.p+l.p == S {
res = append(res, f.i|l.i)
}
}
}
var resS []string
for _, l := range res {
resS = append(resS, conv(l))
}
sort.Strings(resS)
for _, s := range resS {
fmt.Println(s)
}
}