結果
問題 | No.859 路線A、路線B、路線C |
ユーザー | tenten |
提出日時 | 2023-03-15 14:03:07 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 55 ms / 1,000 ms |
コード長 | 3,126 bytes |
コンパイル時間 | 2,753 ms |
コンパイル使用メモリ | 85,172 KB |
実行使用メモリ | 50,428 KB |
最終ジャッジ日時 | 2024-09-18 08:43:57 |
合計ジャッジ時間 | 4,567 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 55 ms
49,976 KB |
testcase_01 | AC | 54 ms
50,188 KB |
testcase_02 | AC | 54 ms
50,428 KB |
testcase_03 | AC | 55 ms
50,388 KB |
testcase_04 | AC | 55 ms
50,340 KB |
testcase_05 | AC | 53 ms
36,612 KB |
testcase_06 | AC | 54 ms
37,352 KB |
testcase_07 | AC | 53 ms
37,192 KB |
testcase_08 | AC | 54 ms
37,244 KB |
testcase_09 | AC | 53 ms
37,184 KB |
testcase_10 | AC | 54 ms
36,980 KB |
testcase_11 | AC | 54 ms
37,160 KB |
testcase_12 | AC | 52 ms
37,252 KB |
testcase_13 | AC | 54 ms
36,744 KB |
testcase_14 | AC | 52 ms
37,264 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[] sizes = new int[3]; for (int i = 0; i < 3; i++) { sizes[i] = sc.nextInt(); } long[][] distances = new long[8][8]; for (int i = 0; i < 8; i++) { Arrays.fill(distances[i], Long.MAX_VALUE / 2); distances[i][i] = 0; } for (int i = 0; i < 3; i++) { distances[i * 2][i * 2 + 1] = sizes[i] - 1; distances[i * 2 + 1][i * 2] = sizes[i] - 1; } for (int i = 0; i < 3; i++) { distances[i * 2][(i * 2 + 2) % 6] = 1; distances[(i * 2 + 2) % 6][i * 2] = 1; distances[i * 2 + 1][(i * 2 + 3) % 6] = 1; distances[(i * 2 + 3) % 6][i * 2 + 1] = 1; } int prevIdx = -1; int prevStation = -1; for (int i = 0; i < 2; i++) { int idx = sc.next().charAt(0) - 'A'; int station = sc.nextInt(); distances[6 + i][idx * 2] = station - 1; distances[idx * 2][6 + i] = station - 1; distances[6 + i][idx * 2 + 1] = sizes[idx] - station; distances[idx * 2 + 1][6 + i] = sizes[idx] - station; if (idx == prevIdx) { distances[6][7] = Math.abs(station - prevStation); distances[7][6] = Math.abs(station - prevStation); } prevIdx = idx; prevStation = station; } for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { for (int k = 0; k < 8; k++) { distances[j][k] = Math.min(distances[j][k], distances[j][i] + distances[i][k]); } } } System.out.println(distances[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(); } }