結果

問題 No.139 交差点
ユーザー chocoruskchocorusk
提出日時 2020-10-03 12:56:24
言語 Java21
(openjdk 21)
結果
AC  
実行時間 157 ms / 5,000 ms
コード長 784 bytes
コンパイル時間 2,147 ms
コンパイル使用メモリ 74,240 KB
実行使用メモリ 56,352 KB
最終ジャッジ日時 2023-09-25 05:04:51
合計ジャッジ時間 7,952 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
55,944 KB
testcase_01 AC 123 ms
56,240 KB
testcase_02 AC 123 ms
55,908 KB
testcase_03 AC 141 ms
56,308 KB
testcase_04 AC 136 ms
55,992 KB
testcase_05 AC 133 ms
56,208 KB
testcase_06 AC 127 ms
55,672 KB
testcase_07 AC 140 ms
55,740 KB
testcase_08 AC 141 ms
55,936 KB
testcase_09 AC 136 ms
55,680 KB
testcase_10 AC 157 ms
55,984 KB
testcase_11 AC 125 ms
55,928 KB
testcase_12 AC 141 ms
55,596 KB
testcase_13 AC 123 ms
56,336 KB
testcase_14 AC 136 ms
56,284 KB
testcase_15 AC 155 ms
55,916 KB
testcase_16 AC 122 ms
55,720 KB
testcase_17 AC 138 ms
56,016 KB
testcase_18 AC 135 ms
56,264 KB
testcase_19 AC 146 ms
55,932 KB
testcase_20 AC 132 ms
55,720 KB
testcase_21 AC 131 ms
55,904 KB
testcase_22 AC 120 ms
53,388 KB
testcase_23 AC 148 ms
56,200 KB
testcase_24 AC 119 ms
55,676 KB
testcase_25 AC 128 ms
56,352 KB
testcase_26 AC 131 ms
55,704 KB
testcase_27 AC 126 ms
55,840 KB
testcase_28 AC 128 ms
56,056 KB
testcase_29 AC 135 ms
56,056 KB
testcase_30 AC 137 ms
56,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scanner=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out);
		int n=scanner.nextInt();
		int l=scanner.nextInt();
		int[] x=new int[n];
		int[] w=new int[n];
		int[] t=new int[n];
		for(int i=0; i<n; i++) {
			x[i]=scanner.nextInt();
			w[i]=scanner.nextInt();
			t[i]=scanner.nextInt();
		}
		int p=0;
		for(int i=0; i<n; i++) {
			if(i==0) p+=x[i];
			else p+=x[i]-(x[i-1]+w[i-1]);
			if(p/t[i]%2==1) {
				p=(p/t[i]+1)*t[i]+w[i];
			}else {
				int p0=p/t[i]*t[i];
				if(t[i]-(p-p0)<w[i]) {
					p=p0+2*t[i]+w[i];
				}else {
					p+=w[i];
				}
			}
		}
		p+=l-(x[n-1]+w[n-1]);
		out.println(p);
		out.close();
		scanner.close();
	}
}
0