結果
問題 | No.859 路線A、路線B、路線C |
ユーザー | tenten |
提出日時 | 2020-10-21 19:12:40 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 130 ms / 1,000 ms |
コード長 | 2,360 bytes |
コンパイル時間 | 2,956 ms |
コンパイル使用メモリ | 77,432 KB |
実行使用メモリ | 55,976 KB |
最終ジャッジ日時 | 2023-09-28 14:18:08 |
合計ジャッジ時間 | 6,481 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 129 ms
55,632 KB |
testcase_01 | AC | 129 ms
55,444 KB |
testcase_02 | AC | 127 ms
55,668 KB |
testcase_03 | AC | 129 ms
55,436 KB |
testcase_04 | AC | 128 ms
55,772 KB |
testcase_05 | AC | 128 ms
55,436 KB |
testcase_06 | AC | 130 ms
55,440 KB |
testcase_07 | AC | 129 ms
55,896 KB |
testcase_08 | AC | 128 ms
55,976 KB |
testcase_09 | AC | 126 ms
53,708 KB |
testcase_10 | AC | 130 ms
55,600 KB |
testcase_11 | AC | 128 ms
55,844 KB |
testcase_12 | AC | 130 ms
55,756 KB |
testcase_13 | AC | 130 ms
55,908 KB |
testcase_14 | AC | 128 ms
55,636 KB |
ソースコード
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(); char stype = sc.next().charAt(0); int s = sc.nextInt(); char ttype = sc.next().charAt(0); int t = sc.nextInt(); long[][] dist = new long[8][8]; for (int i = 0; i < 8; i++) { Arrays.fill(dist[i], Long.MAX_VALUE / 10); dist[i][i] = 0; } dist[0][2] = 1; dist[0][4] = 1; dist[2][4] = 1; dist[1][3] = 1; dist[1][5] = 1; dist[3][5] = 1; dist[0][1] = x - 1; dist[2][3] = y - 1; dist[4][5] = z - 1; dist[2][0] = 1; dist[4][0] = 1; dist[4][2] = 1; dist[3][1] = 1; dist[5][1] = 1; dist[5][3] = 1; dist[1][0] = x - 1; dist[3][2] = y - 1; dist[5][4] = z - 1; if (stype == 'A') { dist[0][6] = s - 1; dist[6][0] = s - 1; dist[1][6] = x - s; dist[6][1] = x - s; } else if (stype == 'B') { dist[2][6] = s - 1; dist[6][2] = s - 1; dist[3][6] = y - s; dist[6][3] = y - s; } else { dist[4][6] = s - 1; dist[6][4] = s - 1; dist[5][6] = z - s; dist[6][5] = z - s; } if (ttype == 'A') { dist[0][7] = t - 1; dist[7][0] = t - 1; dist[1][7] = x - t; dist[7][1] = x - t; } else if (ttype == 'B') { dist[2][7] = t - 1; dist[7][2] = t - 1; dist[3][7] = y - t; dist[7][3] = y - t; } else { dist[4][7] = t - 1; dist[7][4] = t - 1; dist[5][7] = z - t; dist[7][5] = z - t; } if (stype == ttype) { dist[6][7] = Math.abs(s - t); dist[7][6] = Math.abs(s - t); } for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { for (int k = 0; k < 8; k++) { dist[j][k] = Math.min(dist[j][k], dist[j][i] + dist[i][k]); } } } System.out.println(dist[6][7]); } }