結果

問題 No.126 2基のエレベータ
ユーザー takeya_okino
提出日時 2019-09-12 23:28:59
言語 Java
(openjdk 23)
結果
AC  
実行時間 133 ms / 5,000 ms
コード長 646 bytes
コンパイル時間 2,385 ms
コンパイル使用メモリ 74,316 KB
実行使用メモリ 41,540 KB
最終ジャッジ日時 2024-10-10 18:34:37
合計ジャッジ時間 7,160 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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 = 0;
    if(Math.abs(a - s) <= Math.abs(b - s)) {
      ans = Math.abs(a - s) + s;
    } else {
      ans = Math.abs(b - s) + Math.abs(a - s) + a;
      if(a == 0) ans++;
      if(a == 0) {
        ans = Math.min(ans, Math.abs(b - s) + Math.abs(s - 1) + 2);
      } else {
        ans = Math.min(ans, Math.abs(b - s) + Math.abs(s - 1) + a);
      }
    }
    if(s == 1) ans = Math.abs(a - s) + 1;
    System.out.println(ans);
  }
}
0