結果

問題 No.859 路線A、路線B、路線C
ユーザー tentententen
提出日時 2023-01-10 16:37:29
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 3,011 bytes
コンパイル時間 2,452 ms
コンパイル使用メモリ 85,624 KB
実行使用メモリ 49,792 KB
最終ジャッジ日時 2023-08-23 10:14:16
合計ジャッジ時間 4,379 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,428 KB
testcase_01 AC 43 ms
49,436 KB
testcase_02 AC 44 ms
49,236 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 43 ms
49,792 KB
testcase_06 AC 43 ms
49,200 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 44 ms
49,444 KB
testcase_11 AC 44 ms
49,596 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 43 ms
49,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
    }
    
}
0