結果

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

ソースコード

diff #

import java.math.*;
import java.util.*;

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