結果
問題 |
No.1701 half price
|
ユーザー |
|
提出日時 | 2021-12-20 13:03:51 |
言語 | Go (1.23.4) |
結果 |
AC
|
実行時間 | 674 ms / 3,000 ms |
コード長 | 938 bytes |
コンパイル時間 | 11,989 ms |
コンパイル使用メモリ | 231,208 KB |
実行使用メモリ | 143,488 KB |
最終ジャッジ日時 | 2024-09-15 15:18:04 |
合計ジャッジ時間 | 13,298 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
ソースコード
package main import ( "fmt" "bufio" "os" "strconv" ) type Cell struct { n int s string } func newCell(n int, s string) *Cell { cp := new(Cell) cp.n = n cp.s = s return cp } 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, "") for i := 0; i < N; i++ { w1 := make([]*Cell, 0) for _, wv := range w0 { w, v := wv.n, wv.s w1 = append(w1, newCell(w, v)) if w + a[i] / 2 <= W { w1 = append(w1, newCell(w + a[i] / 2, v + strconv.Itoa(i) + ",")) } if w + a[i] <= W { w1 = append(w1, newCell(w + a[i], v + strconv.Itoa(i) + ",")) } } w0 = w1 } if W == 0 { w0 = w0[1:] } m := make(map[string]bool) for _, xy := range w0 { if xy.n == W { m[xy.s] = true } } fmt.Fprintln(w, len(m)) }