結果
問題 | No.859 路線A、路線B、路線C |
ユーザー | Grenache |
提出日時 | 2019-08-09 22:21:35 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,978 bytes |
コンパイル時間 | 4,818 ms |
コンパイル使用メモリ | 79,724 KB |
実行使用メモリ | 42,060 KB |
最終ジャッジ日時 | 2024-07-19 12:19:31 |
合計ジャッジ時間 | 6,783 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 136 ms
41,336 KB |
testcase_01 | AC | 127 ms
41,560 KB |
testcase_02 | AC | 130 ms
41,832 KB |
testcase_03 | AC | 127 ms
42,060 KB |
testcase_04 | AC | 134 ms
41,316 KB |
testcase_05 | AC | 125 ms
41,568 KB |
testcase_06 | AC | 131 ms
41,648 KB |
testcase_07 | AC | 128 ms
41,544 KB |
testcase_08 | AC | 138 ms
41,704 KB |
testcase_09 | WA | - |
testcase_10 | AC | 137 ms
41,436 KB |
testcase_11 | AC | 131 ms
41,852 KB |
testcase_12 | AC | 138 ms
41,684 KB |
testcase_13 | AC | 136 ms
41,716 KB |
testcase_14 | AC | 139 ms
41,344 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, t0 - 1 + x - t1 + y + 1); min = Math.min(min, t1 - 1 + x - t0 + y + 1); min = Math.min(min, t0 - 1 + x - t1 + z + 1); min = Math.min(min, t1 - 1 + x - t0 + z + 1); } else if (s0 == 'B' && s1 == 'B') { min = Math.min(min, Math.abs(t0 - t1)); min = Math.min(min, t0 - 1 + y - t1 + x + 1); min = Math.min(min, t1 - 1 + y - t0 + x + 1); min = Math.min(min, t0 - 1 + y - t1 + z + 1); min = Math.min(min, t1 - 1 + y - t0 + z + 1); } else if (s0 == 'C' && s1 == 'C') { min = Math.min(min, Math.abs(t0 - t1)); min = Math.min(min, t0 - 1 + z - t1 + x + 1); min = Math.min(min, t1 - 1 + z - t0 + x + 1); min = Math.min(min, t0 - 1 + z - t1 + y + 1); min = Math.min(min, t1 - 1 + z - t0 + y + 1); } 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); } } }