結果
問題 | No.859 路線A、路線B、路線C |
ユーザー | Grenache |
提出日時 | 2019-08-09 22:39:03 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 116 ms / 1,000 ms |
コード長 | 4,028 bytes |
コンパイル時間 | 4,479 ms |
コンパイル使用メモリ | 79,744 KB |
実行使用メモリ | 52,816 KB |
最終ジャッジ日時 | 2024-07-19 14:42:42 |
合計ジャッジ時間 | 6,173 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 105 ms
52,816 KB |
testcase_01 | AC | 113 ms
40,944 KB |
testcase_02 | AC | 104 ms
39,928 KB |
testcase_03 | AC | 106 ms
40,276 KB |
testcase_04 | AC | 115 ms
41,204 KB |
testcase_05 | AC | 111 ms
41,136 KB |
testcase_06 | AC | 102 ms
40,204 KB |
testcase_07 | AC | 114 ms
40,944 KB |
testcase_08 | AC | 102 ms
39,944 KB |
testcase_09 | AC | 111 ms
41,220 KB |
testcase_10 | AC | 104 ms
39,992 KB |
testcase_11 | AC | 105 ms
40,276 KB |
testcase_12 | AC | 103 ms
40,192 KB |
testcase_13 | AC | 116 ms
41,196 KB |
testcase_14 | AC | 114 ms
40,968 KB |
ソースコード
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)); } else { throw new RuntimeException(); } pr.println(min); } private static int x; private static int y; private static int z; private static long A1(int t) { return t - 1; } private static long Ax(int t) { return x - t; } private static long B1(int t) { return t - 1; } private static long By(int t) { return y - t; } private static long C1(int t) { return t - 1; } private static long 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); } } }