結果

問題 No.859 路線A、路線B、路線C
ユーザー GrenacheGrenache
提出日時 2019-08-09 22:25:41
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 3,978 bytes
コンパイル時間 4,073 ms
コンパイル使用メモリ 79,504 KB
実行使用メモリ 54,124 KB
最終ジャッジ日時 2024-07-19 12:28:16
合計ジャッジ時間 6,687 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
40,164 KB
testcase_01 AC 130 ms
41,104 KB
testcase_02 AC 131 ms
41,324 KB
testcase_03 AC 129 ms
41,328 KB
testcase_04 AC 118 ms
40,256 KB
testcase_05 AC 133 ms
41,400 KB
testcase_06 AC 119 ms
40,088 KB
testcase_07 AC 131 ms
41,448 KB
testcase_08 AC 131 ms
41,172 KB
testcase_09 WA -
testcase_10 AC 130 ms
41,240 KB
testcase_11 AC 118 ms
40,272 KB
testcase_12 AC 132 ms
41,492 KB
testcase_13 AC 117 ms
40,160 KB
testcase_14 AC 119 ms
39,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.Scanner;


public class Main_yukicoder859 {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		x = sc.nextInt();
		y = sc.nextInt();
		z = sc.nextInt();
		
		char s0 = sc.next().toCharArray()[0];
		int t0 = sc.nextInt();

		char s1 = sc.next().toCharArray()[0];
		int t1 = sc.nextInt();

		long min = Long.MAX_VALUE;
		if (s0 == 'A' && s1 == 'A') {
			min = Math.min(min, Math.abs(t0 - t1));
			min = Math.min(min, A1(t0) + 1 + y + Ax(t1));
			min = Math.min(min, A1(t1) + 1 + y + Ax(t0));
			min = Math.min(min, A1(t0) + 1 + z + Ax(t1));
			min = Math.min(min, A1(t1) + 1 + z + Ax(t0));
		} else if (s0 == 'B' && s1 == 'B') {
			min = Math.min(min, Math.abs(t0 - t1));
			min = Math.min(min, B1(t0) + 1 + x + By(t1));
			min = Math.min(min, B1(t1) + 1 + x + By(t0));
			min = Math.min(min, B1(t0) + 1 + z + By(t1));
			min = Math.min(min, B1(t1) + 1 + z + By(t0));
		} else if (s0 == 'C' && s1 == 'C') {
			min = Math.min(min, Math.abs(t0 - t1));
			min = Math.min(min, C1(t0) + 1 + x + Cz(t1));
			min = Math.min(min, C1(t1) + 1 + x + Cz(t0));
			min = Math.min(min, C1(t0) + 1 + y + Cz(t1));
			min = Math.min(min, C1(t1) + 1 + y + Cz(t0));
		} else if (s0 == 'A' && s1 == 'B') {
			min = Math.min(min, A1(t0) + 1 + B1(t1));
			min = Math.min(min, A1(t0) + 1 + z + By(t1));
			min = Math.min(min, Ax(t0) + 1 + By(t1));
			min = Math.min(min, Ax(t0) + 1 + z + B1(t1));
		} else if (s0 == 'A' && s1 == 'C') {
			min = Math.min(min, A1(t0) + 1 + C1(t1));
			min = Math.min(min, A1(t0) + 1 + y + Cz(t1));
			min = Math.min(min, Ax(t0) + 1 + Cz(t1));
			min = Math.min(min, Ax(t0) + 1 + y + C1(t1));
		} else if (s0 == 'B' && s1 == 'C') {
			min = Math.min(min, B1(t0) + 1 + C1(t1));
			min = Math.min(min, B1(t0) + 1 + x + Cz(t1));
			min = Math.min(min, By(t0) + 1 + Cz(t1));
			min = Math.min(min, By(t0) + 1 + x + C1(t1));
		} else if (s0 == 'B' && s1 == 'A') {
			min = Math.min(min, B1(t0) + 1 + A1(t1));
			min = Math.min(min, B1(t0) + 1 + z + Ax(t1));
			min = Math.min(min, By(t0) + 1 + Ax(t1));
			min = Math.min(min, By(t0) + 1 + z + A1(t1));
		} else if (s0 == 'C' && s1 == 'A') {
			min = Math.min(min, C1(t0) + 1 + A1(t1));
			min = Math.min(min, C1(t0) + 1 + y + Ax(t1));
			min = Math.min(min, Cz(t0) + 1 + Ax(t1));
			min = Math.min(min, Cz(t0) + 1 + y + A1(t1));
		} else if (s0 == 'C' && s1 == 'B') {
			min = Math.min(min, C1(t0) + 1 + B1(t1));
			min = Math.min(min, C1(t0) + 1 + x + By(t1));
			min = Math.min(min, Cz(t0) + 1 + By(t1));
			min = Math.min(min, Cz(t0) + 1 + x + B1(t1));
		}
		
		pr.println(min);
	}
	
	private static int x;
	private static int y;
	private static int z;

	private static int A1(int t) {
		return t - 1;
	}

	private static int Ax(int t) {
		
		return x - t;
	}

	private static int B1(int t) {
		return t - 1;
	}

	private static int By(int t) {
		return y - t;
	}

	private static int C1(int t) {
		return t - 1;
	}

	private static int Cz(int t) {
		return z - t;
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);
			
		solve();
			
		pr.close();
		sc.close();
	}

	static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
		
		void printInts(int... a) {
			StringBuilder sb = new StringBuilder(32);
			for (int i = 0, size = a.length; i < size; i++) {
				if (i > 0) {
					sb.append(' ');
				}
				sb.append(a[i]);
			}

			println(sb);
		}
		
		void printLongs(long... a) {
			StringBuilder sb = new StringBuilder(64);
			for (int i = 0, size = a.length; i < size; i++) {
				if (i > 0) {
					sb.append(' ');
				}
				sb.append(a[i]);
			}

			println(sb);
		}
		
		void printStrings(String... a) {
			StringBuilder sb = new StringBuilder(32);
			for (int i = 0, size = a.length; i < size; i++) {
				if (i > 0) {
					sb.append(' ');
				}
				sb.append(a[i]);
			}

			println(sb);
		}
	}
}
0