結果

問題 No.561 東京と京都
ユーザー villachvillach
提出日時 2017-09-20 06:49:19
言語 Java21
(openjdk 21)
結果
AC  
実行時間 156 ms / 2,000 ms
コード長 1,161 bytes
コンパイル時間 3,509 ms
コンパイル使用メモリ 79,496 KB
実行使用メモリ 54,432 KB
最終ジャッジ日時 2024-04-25 15:49:57
合計ジャッジ時間 7,254 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
54,212 KB
testcase_01 AC 123 ms
54,080 KB
testcase_02 AC 122 ms
54,180 KB
testcase_03 AC 116 ms
53,236 KB
testcase_04 AC 112 ms
52,836 KB
testcase_05 AC 125 ms
54,156 KB
testcase_06 AC 123 ms
54,072 KB
testcase_07 AC 125 ms
54,432 KB
testcase_08 AC 127 ms
54,124 KB
testcase_09 AC 129 ms
54,168 KB
testcase_10 AC 127 ms
54,116 KB
testcase_11 AC 136 ms
54,324 KB
testcase_12 AC 144 ms
54,280 KB
testcase_13 AC 148 ms
54,068 KB
testcase_14 AC 139 ms
54,128 KB
testcase_15 AC 155 ms
54,240 KB
testcase_16 AC 143 ms
54,160 KB
testcase_17 AC 155 ms
54,392 KB
testcase_18 AC 145 ms
54,424 KB
testcase_19 AC 145 ms
54,336 KB
testcase_20 AC 156 ms
54,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.Scanner;

public class N561 {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int i, a, b, x;
		ArrayList<Integer> works = new ArrayList<Integer>();
		LinkedList<Integer> visited = new LinkedList<Integer>();
		LinkedList<Integer> queue = new LinkedList<Integer>();
		for(i = 0;i < n;++i){
			works.add(sc.nextInt());
			works.add(sc.nextInt());
			visited.add(0);
			visited.add(0);
		}
		queue.add(0);
		queue.add(1);
		visited.set(0, works.get(0));
		visited.set(1, works.get(1) - d);
		while(queue.size() > 0){
			i = queue.poll();
			x = visited.get(i);
			
			if(i % 2 == 0){
				a = i + 3;
				b = i + 2;
			}else{
				a = i + 1;
				b = i + 2;
			}
			
			if(a < n*2 && works.get(a) + x - d> visited.get(a)){
				visited.set(a, works.get(a) + x - d);
				queue.add(a);
			}
			if(b < n*2 && works.get(b) + x > visited.get(b)){
				visited.set(b, works.get(b) + x);
				queue.add(b);
			}
		}
		
		System.out.println(Collections.max(visited));
	}
}
0