結果

問題 No.126 2基のエレベータ
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2016-11-21 17:35:31
言語 Java21
(openjdk 21)
結果
AC  
実行時間 132 ms / 5,000 ms
コード長 785 bytes
コンパイル時間 1,946 ms
コンパイル使用メモリ 74,192 KB
実行使用メモリ 41,788 KB
最終ジャッジ日時 2024-04-19 01:50:43
合計ジャッジ時間 6,664 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
41,348 KB
testcase_01 AC 125 ms
41,428 KB
testcase_02 AC 125 ms
41,644 KB
testcase_03 AC 125 ms
41,396 KB
testcase_04 AC 128 ms
41,560 KB
testcase_05 AC 131 ms
41,288 KB
testcase_06 AC 125 ms
41,380 KB
testcase_07 AC 127 ms
41,772 KB
testcase_08 AC 128 ms
41,640 KB
testcase_09 AC 131 ms
41,512 KB
testcase_10 AC 126 ms
41,452 KB
testcase_11 AC 125 ms
41,436 KB
testcase_12 AC 125 ms
41,788 KB
testcase_13 AC 114 ms
41,692 KB
testcase_14 AC 129 ms
41,512 KB
testcase_15 AC 128 ms
41,336 KB
testcase_16 AC 124 ms
41,432 KB
testcase_17 AC 113 ms
41,588 KB
testcase_18 AC 123 ms
41,724 KB
testcase_19 AC 127 ms
41,556 KB
testcase_20 AC 129 ms
41,580 KB
testcase_21 AC 132 ms
41,432 KB
testcase_22 AC 124 ms
41,428 KB
testcase_23 AC 125 ms
41,364 KB
testcase_24 AC 127 ms
41,748 KB
testcase_25 AC 126 ms
41,648 KB
testcase_26 AC 124 ms
41,692 KB
testcase_27 AC 127 ms
41,772 KB
testcase_28 AC 127 ms
41,288 KB
testcase_29 AC 116 ms
41,508 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 min=0;
        int Amove=Math.abs(A-S);
        int Bmove=Math.abs(B-S);
        if(S==1){
            min=Amove+1;
        }else{
            if(Amove<=Bmove){
                min=Amove+S;
            }else{
                if(A==0){
                    min=Bmove+S+1;
                }else if(A<B){
                    min=Bmove+S;
                }else{
                    int a=S+A-1;
                    int b=(A-S)+A;
                    min=Bmove+Math.min(a,b);
                }
            }
        }
        System.out.println(min);
    }
}
0