結果

問題 No.139 交差点
ユーザー yukirin
提出日時 2016-03-05 14:00:50
言語 Go
(1.23.4)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 637 bytes
コンパイル時間 10,783 ms
コンパイル使用メモリ 220,632 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-10 23:37:22
合計ジャッジ時間 12,001 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	n, l := nextInt(), nextInt()
	ns := make([][3]int, n)
	for i := 0; i < n; i++ {
		ns[i] = [3]int{nextInt(), nextInt(), nextInt()}
	}

	t, r := 0, 0
	for _, v := range ns {
		x, w, c := v[0], v[1], v[2]
		t, r = t+x-r, x
		div, mod := t/c, t%c

		if div%2 == 1 {
			t += c - mod
		} else if w > c-mod {
			t += c - mod + c
		}

		t, r = t+w, r+w
	}
	fmt.Println(t + l - r)
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextLine())
	return i
}
0