結果
| 問題 |
No.1701 half price
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-12-20 12:46:30 |
| 言語 | Go (1.23.4) |
| 結果 |
AC
|
| 実行時間 | 1,054 ms / 3,000 ms |
| コード長 | 1,219 bytes |
| コンパイル時間 | 12,097 ms |
| コンパイル使用メモリ | 223,052 KB |
| 実行使用メモリ | 346,344 KB |
| 最終ジャッジ日時 | 2024-09-15 15:17:22 |
| 合計ジャッジ時間 | 14,564 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 20 |
ソースコード
package main
import (
"fmt"
"bufio"
"os"
"strings"
"strconv"
"sort"
)
type Cell struct {
n int
a []int
}
func newCell(n int, a []int) *Cell {
cp := new(Cell)
cp.n = n
if len(a) == 0 {
cp.a = a
} else {
cp.a = make([]int, len(a))
copy(cp.a, a)
}
return cp
}
func toString(a []int) string {
sort.Ints(a)
var str_build strings.Builder
for i := 0; i < len(a); i++ {
str_build.WriteString(strconv.Itoa(a[i]) + ",")
}
return str_build.String()
}
func main() {
r := bufio.NewReader(os.Stdin)
w := bufio.NewWriter(os.Stdout)
defer w.Flush()
var N, W int
fmt.Fscan(r, &N, &W)
a := make([]int, N)
for i := 0; i < N; i++ {
fmt.Fscan(r, &a[i])
}
w0 := make([]*Cell, 1)
w0[0] = newCell(0, make([]int, 0))
for i := 0; i < N; i++ {
w1 := make([]*Cell, 0)
for _, wv := range w0 {
w, v := wv.n, wv.a
w1 = append(w1, newCell(w, v))
if w + a[i] / 2 <= W {
w1 = append(w1, newCell(w + a[i] / 2, append(v, i)))
}
if w + a[i] <= W {
w1 = append(w1, newCell(w + a[i], append(v, i)))
}
}
w0 = w1
}
if W == 0 {
w0 = w0[1:]
}
m := make(map[string]bool)
for _, xy := range w0 {
if xy.n == W {
m[toString(xy.a)] = true
}
}
fmt.Fprintln(w, len(m))
}