結果
問題 | No.859 路線A、路線B、路線C |
ユーザー |
|
提出日時 | 2019-08-09 22:25:41 |
言語 | Java (openjdk 23) |
結果 |
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 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 11 WA * 1 |
ソースコード
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);}}}