結果
問題 | No.1037 exhausted |
ユーザー |
![]() |
提出日時 | 2020-04-24 23:35:35 |
言語 | Go (1.23.4) |
結果 |
AC
|
実行時間 | 657 ms / 2,000 ms |
コード長 | 1,631 bytes |
コンパイル時間 | 10,606 ms |
コンパイル使用メモリ | 233,460 KB |
実行使用メモリ | 6,004 KB |
最終ジャッジ日時 | 2024-10-15 03:54:16 |
合計ジャッジ時間 | 15,951 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
package mainimport ("bufio""fmt""math""os""strconv")func min(a, b int) int {if a < b {return a}return b}func main() {defer flush()N := readInt()V := readInt()L := readInt()cx := 0d := map[int]int{}d[V] = 0for i := 0; i < N; i++ {x := readInt()v := readInt()w := readInt()nd := map[int]int{}for k := range d {t := k - (x - cx)if t < 0 {continue}_, ok := nd[t]if !ok || nd[t] > d[k] {nd[t] = d[k]}t = min(t+v, V)_, ok = nd[t]if !ok || nd[t] > d[k]+w {nd[t] = d[k] + w}}if len(nd) == 0 {println(-1)return}d = ndcx = x}result := math.MaxInt64for k := range d {if k-(L-cx) >= 0 {result = min(result, d[k])}}println(result)}const (ioBufferSize = 1 * 1024 * 1024 // 1 MB)var stdinScanner = func() *bufio.Scanner {result := bufio.NewScanner(os.Stdin)result.Buffer(make([]byte, ioBufferSize), ioBufferSize)result.Split(bufio.ScanWords)return result}()func readString() string {stdinScanner.Scan()return stdinScanner.Text()}func readInt() int {result, err := strconv.Atoi(readString())if err != nil {panic(err)}return result}func readInts(n int) []int {result := make([]int, n)for i := 0; i < n; i++ {result[i] = readInt()}return result}var stdoutWriter = bufio.NewWriter(os.Stdout)func flush() {stdoutWriter.Flush()}func printf(f string, args ...interface{}) (int, error) {return fmt.Fprintf(stdoutWriter, f, args...)}func println(args ...interface{}) (int, error) {return fmt.Fprintln(stdoutWriter, args...)}