結果
| 問題 | 
                            No.859 路線A、路線B、路線C
                             | 
                    
| コンテスト | |
| ユーザー | 
                             htensai
                         | 
                    
| 提出日時 | 2020-05-08 15:17:12 | 
| 言語 | Java  (openjdk 23)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,528 bytes | 
| コンパイル時間 | 2,409 ms | 
| コンパイル使用メモリ | 78,360 KB | 
| 実行使用メモリ | 41,540 KB | 
| 最終ジャッジ日時 | 2024-07-03 09:51:33 | 
| 合計ジャッジ時間 | 5,258 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 7 WA * 5 | 
ソースコード
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();
		long[][] costs = new long[8][8];
		for (int i = 0; i < 8; i++) {
		    Arrays.fill(costs[i], Long.MAX_VALUE / 10);
		    costs[i][i] = 0;
		}
		costs[0][1] = x - 1;
		costs[0][2] = 1;
		costs[0][4] = 1;
		costs[1][3] = 1;
		costs[3][5] = 1;
		costs[2][3] = y - 1;
		costs[4][5] = z - 1;
		char sType = sc.next().charAt(0);
		int sIdx = sc.nextInt();
		if (sType == 'A') {
		    costs[6][0] = sIdx - 1;
		    costs[6][1] = x - sIdx;
		} else if (sType == 'B') {
		    costs[6][2] = sIdx - 1;
		    costs[6][3] = y - sIdx;
		} else {
		    costs[6][4] = sIdx - 1;
		    costs[6][5] = z - sIdx;
		}
		char tType = sc.next().charAt(0);
		int tIdx = sc.nextInt();
		if (tType == 'A') {
		    costs[7][0] = tIdx - 1;
		    costs[7][1] = x - tIdx;
		} else if (tType == 'B') {
		    costs[7][2] = tIdx - 1;
		    costs[7][3] = y - tIdx;
		} else {
		    costs[7][4] = tIdx - 1;
		    costs[7][5] = z - tIdx;
		}
		if (sType == tType) {
		    costs[6][7] = Math.abs(sIdx - tIdx);
		}
		for (int i = 0; i < 8; i++) {
		    for (int j = 0; j < 8; j++) {
		        for (int k = 0; k < 8; k++) {
		            costs[j][k] = Math.min(costs[j][k], costs[j][i] + costs[i][k]);
		            costs[j][k] = Math.min(costs[j][k], costs[k][j]);
		            costs[k][j] = costs[j][k];
		        }
		    }
		}
		System.out.println(costs[6][7]);
	}
}
            
            
            
        
            
htensai