結果

問題 No.126 2基のエレベータ
ユーザー tsunatama5
提出日時 2015-02-08 14:47:01
言語 Java
(openjdk 23)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 835 bytes
コンパイル時間 3,837 ms
コンパイル使用メモリ 77,800 KB
実行使用メモリ 54,232 KB
最終ジャッジ日時 2024-11-21 19:41:50
合計ジャッジ時間 9,230 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

package P126;

import java.util.Scanner;

public class P126 {
	
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String r = sc.nextLine();
		String[] rstrs = r.split(" ",0);

		int a = Integer.parseInt(rstrs[0]);
		int b = Integer.parseInt(rstrs[1]);
		int s = Integer.parseInt(rstrs[2]);
		int ans = 0;
		
		if (Math.abs(s-a) <= Math.abs(s-b)) {
			ans = Math.abs(s-a) + (s-0);
		} else if (Math.abs(s-a) > Math.abs(s-b) && a == 0) {
			ans = Math.abs(s-b) + Math.abs(s-1) + Math.abs(a-1) + Math.abs(1-a);
		} else if ((Math.abs(s-a) > Math.abs(s-b) && a != 0)){
			if (Math.abs(s-a)<Math.abs(s-1)) {
				ans = Math.abs(s-b) + Math.abs(s-a) + Math.abs(a);
			} else if (Math.abs(s-a)>=Math.abs(s-1)){
				ans = Math.abs(s-b) + Math.abs(s-1) + Math.abs(a);
			}
		}
		
		System.out.println(ans);
	}
}
0