結果
問題 | No.1037 exhausted |
ユーザー | ccppjsrb |
提出日時 | 2020-06-10 17:55:51 |
言語 | Go (1.22.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,293 bytes |
コンパイル時間 | 15,840 ms |
コンパイル使用メモリ | 244,236 KB |
実行使用メモリ | 33,280 KB |
最終ジャッジ日時 | 2024-06-23 10:20:14 |
合計ジャッジ時間 | 17,394 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | WA | - |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | WA | - |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | WA | - |
testcase_07 | AC | 1 ms
5,376 KB |
testcase_08 | AC | 1 ms
5,376 KB |
testcase_09 | WA | - |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 1 ms
5,376 KB |
testcase_12 | AC | 43 ms
33,152 KB |
testcase_13 | AC | 42 ms
33,152 KB |
testcase_14 | AC | 43 ms
33,024 KB |
testcase_15 | AC | 42 ms
33,152 KB |
testcase_16 | AC | 42 ms
33,024 KB |
testcase_17 | AC | 43 ms
33,152 KB |
testcase_18 | AC | 44 ms
33,152 KB |
testcase_19 | AC | 44 ms
33,152 KB |
testcase_20 | AC | 37 ms
33,024 KB |
testcase_21 | AC | 36 ms
33,152 KB |
testcase_22 | AC | 33 ms
33,280 KB |
ソースコード
package main import ( "bufio" "fmt" "math" "os" "strconv" ) func configure(scanner *bufio.Scanner) { scanner.Split(bufio.ScanWords) scanner.Buffer(make([]byte, 1000005), 1000005) } func getNextString(scanner *bufio.Scanner) string { scanned := scanner.Scan() if !scanned { panic("scan failed") } return scanner.Text() } func getNextInt(scanner *bufio.Scanner) int { i, _ := strconv.Atoi(getNextString(scanner)) return i } func getNextInt64(scanner *bufio.Scanner) int64 { i, _ := strconv.ParseInt(getNextString(scanner), 10, 64) return i } func getNextFloat64(scanner *bufio.Scanner) float64 { i, _ := strconv.ParseFloat(getNextString(scanner), 64) return i } func main() { fp := os.Stdin wfp := os.Stdout extra := 0 if os.Getenv("I") == "IronMan" { fp, _ = os.Open(os.Getenv("END_GAME")) extra = 100 } scanner := bufio.NewScanner(fp) configure(scanner) writer := bufio.NewWriter(wfp) defer func() { r := recover() if r != nil { fmt.Fprintln(writer, r) } writer.Flush() }() solve(scanner, writer) for i := 0; i < extra; i++ { fmt.Fprintln(writer, "-----------------------------------") solve(scanner, writer) } } func solve(scanner *bufio.Scanner, writer *bufio.Writer) { n := getNextInt(scanner) v := getNextInt(scanner) l := getNextInt(scanner) xx := make([]int, n) vv := make([]int, n) ww := make([]int, n) for i := 0; i < n; i++ { xx[i] = getNextInt(scanner) vv[i] = getNextInt(scanner) ww[i] = getNextInt(scanner) } xx = append(xx, l) for i := n; i > 0; i-- { xx[i] -= xx[i-1] } dp := makeGrid(n+2, v+1) for i := 0; i < n+2; i++ { for j := 0; j < v+1; j++ { dp[i][j] = cint(math.MaxInt64) } } dp[0][v] = 0 for i := 0; i < n+1; i++ { for j := xx[i]; j < v+1; j++ { dp[i+1][j-xx[i]].minAs(dp[i][j]) } for j := 1; i < n && j <= vv[i] && v-j >= 0; j++ { if dp[i+1][v-j].sub(math.MaxInt64) == 0 { continue } dp[i+1][v].minAs(dp[i+1][v-j].add(ww[i])) } for j := v; i < n && j >= vv[i]; j-- { if dp[i+1][j-vv[i]].sub(math.MaxInt64) == 0 { continue } dp[i+1][j].minAs(dp[i+1][j-vv[i]].add(ww[i])) } } var ans cint ans = dp[n+1][0] for i := 0; i < v; i++ { ans.minAs(dp[n][i+1]) } if ans.sub(math.MaxInt64) == 0 { ans = -1 } fmt.Fprintln(writer, ans) } func makeGrid(h, w int) [][]cint { index := make([][]cint, h, h) data := make([]cint, h*w, h*w) for i := 0; i < h; i++ { index[i] = data[i*w : (i+1)*w] } return index } type cint int64 func (ct *cint) cintize(x interface{}) cint { if y, isCint := x.(cint); isCint { return y } if y, isInt64 := x.(int64); isInt64 { return cint(y) } return cint(x.(int)) } func (ct *cint) minAs(x interface{}) *cint { *ct = ct.min(x) return ct } func (ct *cint) maxAs(x interface{}) *cint { *ct = ct.max(x) return ct } func (ct cint) min(x interface{}) cint { y := ct.cintize(x) if ct > y { return y } return ct } func (ct cint) max(x interface{}) cint { y := ct.cintize(x) if ct < y { return y } return ct } func (ct cint) add(x interface{}) cint { return ct + ct.cintize(x) } func (ct cint) sub(x interface{}) cint { return ct - ct.cintize(x) } func (ct cint) mul(x interface{}) cint { return ct * ct.cintize(x) } func (ct cint) div(x interface{}) cint { return ct / ct.cintize(x) }