結果

問題 No.126 2基のエレベータ
ユーザー htensaihtensai
提出日時 2020-02-06 09:11:12
言語 Java21
(openjdk 21)
結果
AC  
実行時間 130 ms / 5,000 ms
コード長 590 bytes
コンパイル時間 2,096 ms
コンパイル使用メモリ 74,120 KB
実行使用メモリ 41,960 KB
最終ジャッジ日時 2024-04-19 01:55:48
合計ジャッジ時間 6,927 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
41,140 KB
testcase_01 AC 127 ms
41,332 KB
testcase_02 AC 129 ms
41,632 KB
testcase_03 AC 128 ms
41,820 KB
testcase_04 AC 128 ms
41,188 KB
testcase_05 AC 129 ms
41,588 KB
testcase_06 AC 128 ms
41,424 KB
testcase_07 AC 127 ms
41,676 KB
testcase_08 AC 116 ms
41,396 KB
testcase_09 AC 129 ms
41,136 KB
testcase_10 AC 129 ms
41,116 KB
testcase_11 AC 128 ms
41,400 KB
testcase_12 AC 114 ms
40,320 KB
testcase_13 AC 125 ms
41,348 KB
testcase_14 AC 128 ms
41,552 KB
testcase_15 AC 129 ms
41,432 KB
testcase_16 AC 130 ms
41,152 KB
testcase_17 AC 127 ms
41,108 KB
testcase_18 AC 129 ms
41,360 KB
testcase_19 AC 126 ms
41,960 KB
testcase_20 AC 125 ms
41,440 KB
testcase_21 AC 127 ms
41,152 KB
testcase_22 AC 123 ms
40,232 KB
testcase_23 AC 128 ms
41,248 KB
testcase_24 AC 128 ms
41,404 KB
testcase_25 AC 124 ms
41,292 KB
testcase_26 AC 123 ms
41,572 KB
testcase_27 AC 125 ms
41,564 KB
testcase_28 AC 123 ms
41,464 KB
testcase_29 AC 127 ms
41,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int s = sc.nextInt();
        int ans;
        if (s == 1 || Math.abs(s - a) <= Math.abs(s - b)) {
            ans = Math.abs(s - a) + s;
        } else if (a == 0) {
            ans = Math.abs(s - b) + s + 1;
        } else {
            ans = Math.min(Math.abs(s - b) + s - 1 + Math.abs(a - 1) + 1, Math.abs(s - b) + Math.abs(s - a) + a);
        }
        System.out.println(ans);
    }
}
0