結果

問題 No.859 路線A、路線B、路線C
ユーザー htensaihtensai
提出日時 2020-05-08 15:17:12
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,528 bytes
コンパイル時間 2,137 ms
コンパイル使用メモリ 73,980 KB
実行使用メモリ 56,164 KB
最終ジャッジ日時 2023-09-16 08:28:09
合計ジャッジ時間 5,463 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,872 KB
testcase_01 AC 128 ms
55,748 KB
testcase_02 AC 125 ms
55,848 KB
testcase_03 AC 126 ms
55,568 KB
testcase_04 AC 125 ms
55,932 KB
testcase_05 AC 126 ms
55,828 KB
testcase_06 AC 124 ms
55,796 KB
testcase_07 AC 125 ms
55,520 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 125 ms
55,768 KB
testcase_12 WA -
testcase_13 AC 130 ms
55,680 KB
testcase_14 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		int z = sc.nextInt();
		long[][] costs = new long[8][8];
		for (int i = 0; i < 8; i++) {
		    Arrays.fill(costs[i], Long.MAX_VALUE / 10);
		    costs[i][i] = 0;
		}
		costs[0][1] = x - 1;
		costs[0][2] = 1;
		costs[0][4] = 1;
		costs[1][3] = 1;
		costs[3][5] = 1;
		costs[2][3] = y - 1;
		costs[4][5] = z - 1;
		char sType = sc.next().charAt(0);
		int sIdx = sc.nextInt();
		if (sType == 'A') {
		    costs[6][0] = sIdx - 1;
		    costs[6][1] = x - sIdx;
		} else if (sType == 'B') {
		    costs[6][2] = sIdx - 1;
		    costs[6][3] = y - sIdx;
		} else {
		    costs[6][4] = sIdx - 1;
		    costs[6][5] = z - sIdx;
		}
		char tType = sc.next().charAt(0);
		int tIdx = sc.nextInt();
		if (tType == 'A') {
		    costs[7][0] = tIdx - 1;
		    costs[7][1] = x - tIdx;
		} else if (tType == 'B') {
		    costs[7][2] = tIdx - 1;
		    costs[7][3] = y - tIdx;
		} else {
		    costs[7][4] = tIdx - 1;
		    costs[7][5] = z - tIdx;
		}
		if (sType == tType) {
		    costs[6][7] = Math.abs(sIdx - tIdx);
		}
		for (int i = 0; i < 8; i++) {
		    for (int j = 0; j < 8; j++) {
		        for (int k = 0; k < 8; k++) {
		            costs[j][k] = Math.min(costs[j][k], costs[j][i] + costs[i][k]);
		            costs[j][k] = Math.min(costs[j][k], costs[k][j]);
		            costs[k][j] = costs[j][k];
		        }
		    }
		}
		System.out.println(costs[6][7]);
	}
}
0