結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,904 KB
testcase_01 AC 125 ms
54,156 KB
testcase_02 AC 125 ms
55,520 KB
testcase_03 AC 125 ms
55,696 KB
testcase_04 AC 124 ms
55,856 KB
testcase_05 AC 126 ms
55,696 KB
testcase_06 AC 124 ms
56,228 KB
testcase_07 AC 125 ms
55,780 KB
testcase_08 AC 125 ms
55,548 KB
testcase_09 AC 125 ms
55,892 KB
testcase_10 AC 125 ms
55,548 KB
testcase_11 AC 123 ms
55,836 KB
testcase_12 AC 123 ms
55,956 KB
testcase_13 AC 125 ms
56,168 KB
testcase_14 AC 123 ms
55,976 KB
権限があれば一括ダウンロードができます

ソースコード

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[2][4] = 1;
		costs[1][3] = 1;
		costs[1][5] = 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