結果

問題 No.139 交差点
ユーザー Grenache
提出日時 2016-02-12 20:12:06
言語 Java
(openjdk 23)
結果
AC  
実行時間 161 ms / 5,000 ms
コード長 909 bytes
コンパイル時間 3,262 ms
コンパイル使用メモリ 77,116 KB
実行使用メモリ 54,420 KB
最終ジャッジ日時 2024-09-22 04:13:52
合計ジャッジ時間 8,771 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;


public class Main_yukicoder139 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int l = sc.nextInt();

        int[] x = new int[n + 1];
        int[] w = new int[n + 1];
        int[] t = new int[n + 1];

        for (int i = 0; i < n; i++) {
        	x[i + 1] = sc.nextInt();
        	w[i + 1] = sc.nextInt();
        	t[i + 1] = sc.nextInt();
        }

        long time = 0;
        for (int i = 1; i <= n; i++) {
        	time += x[i] - (x[i - 1] + w[i - 1]);

        	if (time / t[i] % 2 == 1) {
        		time += t[i] - time % t[i];
        	} else if ((time + w[i]) / t[i] % 2 == 1 && (time + w[i]) % t[i] != 0) {
        		time += t[i] - time % t[i] + t[i];
        	}

        	time += w[i];
        }

        System.out.println(time + l - (x[n] + w[n]));

        sc.close();
    }
}
0