結果

問題 No.126 2基のエレベータ
ユーザー tsunabit
提出日時 2020-03-03 21:53:41
言語 Java
(openjdk 23)
結果
AC  
実行時間 137 ms / 5,000 ms
コード長 512 bytes
コンパイル時間 3,298 ms
コンパイル使用メモリ 76,348 KB
実行使用メモリ 54,356 KB
最終ジャッジ日時 2024-10-10 18:36:14
合計ジャッジ時間 8,221 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class No126 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(), b = sc.nextInt(), s = sc.nextInt();
		int t = 0;
		if(Math.abs(a-s) <= Math.abs(b-s) || s == 1) {
			t = Math.abs(a-s) + s;
		}else {
			// 1階へ
			t = Math.abs(b-s) + (s-1) + Math.abs(a-1) + 1;
			// Aへ
			int u = Math.abs(b-s) + Math.abs(a-s) + Math.abs(a-1) + 1;
			t = Math.min(t, u);
		}
		System.out.println(t);
	}
}
0