結果
問題 | No.859 路線A、路線B、路線C |
ユーザー | tenten |
提出日時 | 2023-01-10 16:37:29 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,011 bytes |
コンパイル時間 | 2,693 ms |
コンパイル使用メモリ | 91,540 KB |
実行使用メモリ | 50,492 KB |
最終ジャッジ日時 | 2024-06-01 07:52:09 |
合計ジャッジ時間 | 4,386 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 56 ms
50,188 KB |
testcase_01 | AC | 58 ms
50,164 KB |
testcase_02 | AC | 56 ms
50,160 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | AC | 55 ms
50,468 KB |
testcase_06 | AC | 56 ms
50,368 KB |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | AC | 55 ms
50,480 KB |
testcase_11 | AC | 53 ms
50,164 KB |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | AC | 56 ms
50,212 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int[] counts = new int[3]; for (int i = 0; i < 3; i++) { counts[i] = sc.nextInt(); } int[] target = new int[2]; int[] station = new int[2]; for (int i = 0; i < 2; i++) { target[i] = sc.next().charAt(0) - 'A'; station[i] = sc.nextInt(); } long[][] distance = new long[8][8]; for (int i = 0; i < 8; i++) { Arrays.fill(distance[i], Long.MAX_VALUE / 2); distance[i][i] = 0; } for (int i = 0; i < 3; i++) { distance[i * 2][i * 2 + 1] = counts[i] - 1; distance[i * 2 + 1][i * 2] = counts[i] - 1; distance[i * 2][(i + 1) % 3 * 2] = 1; distance[i * 2 + 1][(i + 1) % 3 * 2 + 1] = 1; } for (int i = 0; i < 2; i++) { distance[target[i] * 2][6 + i] = station[i] - 1; distance[6 + i][target[i] * 2] = station[i] - 1; distance[target[i] * 2 + 1][6 + i] = counts[target[i]] - station[i]; distance[6 + i][target[i] * 2 + 1] = counts[target[i]] - station[i]; } if (target[0] == target[1]) { distance[6][7] = Math.abs(station[0] - station[1]); distance[7][6] = Math.abs(station[0] - station[1]); } for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { for (int k = 0; k < 8; k++) { distance[j][k] = Math.min(distance[j][k], distance[j][i] + distance[i][k]); } } } System.out.println(distance[6][7]); } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }