結果
問題 | No.859 路線A、路線B、路線C |
ユーザー | tenten |
提出日時 | 2023-03-15 12:49:21 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,118 bytes |
コンパイル時間 | 3,403 ms |
コンパイル使用メモリ | 92,476 KB |
実行使用メモリ | 37,312 KB |
最終ジャッジ日時 | 2024-09-18 08:41:52 |
合計ジャッジ時間 | 4,161 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 47 ms
36,996 KB |
testcase_01 | AC | 48 ms
36,980 KB |
testcase_02 | WA | - |
testcase_03 | AC | 47 ms
37,188 KB |
testcase_04 | AC | 48 ms
36,852 KB |
testcase_05 | AC | 47 ms
36,888 KB |
testcase_06 | AC | 46 ms
36,952 KB |
testcase_07 | AC | 48 ms
36,976 KB |
testcase_08 | AC | 48 ms
37,164 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 48 ms
37,132 KB |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | AC | 46 ms
37,204 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]; distances[i * 2 + 1][i * 2] = sizes[i]; } 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(); } }