結果

問題 No.126 2基のエレベータ
ユーザー htensai
提出日時 2020-02-06 09:11:12
言語 Java
(openjdk 23)
結果
AC  
実行時間 133 ms / 5,000 ms
コード長 590 bytes
コンパイル時間 2,027 ms
コンパイル使用メモリ 74,652 KB
実行使用メモリ 41,748 KB
最終ジャッジ日時 2024-10-10 18:35:28
合計ジャッジ時間 6,908 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

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