結果

問題 No.126 2基のエレベータ
ユーザー kenji_shioya
提出日時 2016-06-25 18:19:25
言語 Java
(openjdk 23)
結果
AC  
実行時間 132 ms / 5,000 ms
コード長 727 bytes
コンパイル時間 3,395 ms
コンパイル使用メモリ 74,660 KB
実行使用メモリ 41,708 KB
最終ジャッジ日時 2024-10-10 18:30:32
合計ジャッジ時間 8,054 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Exercise126{
  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(a == b || s == 1 || s == a || Math.abs(s - a) <= Math.abs(s - b)){
      ans = Math.abs(s - a) + (s - 0);
    }else{
      if(a < b){
        if(a > 0){
          ans = Math.abs(s - b) + (s - a) + (a - 0);
        }else{
          ans = Math.abs(s - b) + (s - 1) + 2;
        }
      }else{
        if(s > a / 2){
          ans = Math.abs(s - b) + (a - s) + (a - 0);
        }else{
          ans = Math.abs(s - b) + (s - 1) + (a - 0);
        }
      }
    }
    System.out.println(ans);
	}
}
0