結果

問題 No.126 2基のエレベータ
ユーザー tsunatama5
提出日時 2015-09-21 00:15:27
言語 Java
(openjdk 23)
結果
AC  
実行時間 130 ms / 5,000 ms
コード長 916 bytes
コンパイル時間 3,489 ms
コンパイル使用メモリ 77,292 KB
実行使用メモリ 41,708 KB
最終ジャッジ日時 2024-10-10 18:27:45
合計ジャッジ時間 8,198 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

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 (s == 1) {
			ans = Math.abs(s-a) + 1;
		} else if (Math.abs(s-a) <= Math.abs(s-b) && s != 1) {
			ans = Math.abs(s-a) + (s-0);
		} else if (Math.abs(s-a) > Math.abs(s-b) && a == 0 && s != 1) {
			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 && s != 1)){
			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