結果

問題 No.139 交差点
ユーザー uafr_csuafr_cs
提出日時 2015-08-17 15:48:40
言語 Java21
(openjdk 21)
結果
AC  
実行時間 159 ms / 5,000 ms
コード長 1,235 bytes
コンパイル時間 3,450 ms
コンパイル使用メモリ 74,984 KB
実行使用メモリ 57,476 KB
最終ジャッジ日時 2023-09-25 12:35:19
合計ジャッジ時間 8,730 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
53,696 KB
testcase_01 AC 125 ms
55,932 KB
testcase_02 AC 125 ms
56,132 KB
testcase_03 AC 128 ms
55,780 KB
testcase_04 AC 137 ms
55,860 KB
testcase_05 AC 141 ms
55,844 KB
testcase_06 AC 128 ms
55,704 KB
testcase_07 AC 142 ms
57,476 KB
testcase_08 AC 136 ms
56,428 KB
testcase_09 AC 139 ms
54,040 KB
testcase_10 AC 152 ms
56,036 KB
testcase_11 AC 131 ms
55,872 KB
testcase_12 AC 159 ms
55,672 KB
testcase_13 AC 127 ms
55,692 KB
testcase_14 AC 140 ms
55,864 KB
testcase_15 AC 149 ms
55,936 KB
testcase_16 AC 129 ms
55,516 KB
testcase_17 AC 144 ms
55,872 KB
testcase_18 AC 142 ms
56,100 KB
testcase_19 AC 145 ms
55,792 KB
testcase_20 AC 135 ms
55,744 KB
testcase_21 AC 124 ms
55,928 KB
testcase_22 AC 124 ms
55,644 KB
testcase_23 AC 159 ms
56,232 KB
testcase_24 AC 129 ms
55,500 KB
testcase_25 AC 137 ms
55,752 KB
testcase_26 AC 133 ms
55,640 KB
testcase_27 AC 129 ms
55,736 KB
testcase_28 AC 127 ms
55,860 KB
testcase_29 AC 141 ms
55,796 KB
testcase_30 AC 142 ms
56,020 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Set;

public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		final long L = sc.nextLong();
		
		int[] xs = new int[N];
		int[] ws = new int[N];
		long[] Ts = new long[N];
		
		for(int i = 0; i < N; i++){
			final int x = sc.nextInt();
			final int w = sc.nextInt();
			final long T = sc.nextLong();
			
			xs[i] = x;
			ws[i] = w;
			Ts[i] = T;
		}
		
		long total_time = 0;
		for(int i = 0; i < N; i++){
			final long arrival_time = total_time + (xs[i] - (i == 0 ? 0 : (xs[i - 1] + ws[i - 1])));
			final long walk_time = Math.max(0, Ts[i] - arrival_time % (2 * Ts[i]));
			
			if(walk_time >= ws[i]){
				total_time = arrival_time + ws[i];
			}else{
				final long arrival_wait_time = (arrival_time + (2 * Ts[i] - 1)) / (2 * Ts[i]) * (2 * Ts[i]);
				total_time = arrival_wait_time + ws[i];
			}
			
			//System.out.println(arrival_time + " " + walk_time + " " + total_time);
		}
		total_time += (L - (xs[N - 1] + ws[N - 1]));
		
		System.out.println(total_time);
	}
	
}
0