結果

問題 No.126 2基のエレベータ
ユーザー tsunabittsunabit
提出日時 2020-03-03 21:53:41
言語 Java21
(openjdk 21)
結果
AC  
実行時間 128 ms / 5,000 ms
コード長 512 bytes
コンパイル時間 5,324 ms
コンパイル使用メモリ 74,948 KB
実行使用メモリ 41,384 KB
最終ジャッジ日時 2024-04-19 01:56:36
合計ジャッジ時間 7,685 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
40,880 KB
testcase_01 AC 104 ms
39,832 KB
testcase_02 AC 113 ms
41,072 KB
testcase_03 AC 108 ms
40,720 KB
testcase_04 AC 124 ms
41,384 KB
testcase_05 AC 120 ms
41,012 KB
testcase_06 AC 111 ms
41,072 KB
testcase_07 AC 113 ms
41,340 KB
testcase_08 AC 120 ms
41,120 KB
testcase_09 AC 109 ms
40,004 KB
testcase_10 AC 128 ms
40,916 KB
testcase_11 AC 109 ms
39,832 KB
testcase_12 AC 106 ms
39,964 KB
testcase_13 AC 118 ms
41,160 KB
testcase_14 AC 109 ms
40,248 KB
testcase_15 AC 112 ms
40,608 KB
testcase_16 AC 113 ms
40,248 KB
testcase_17 AC 115 ms
41,128 KB
testcase_18 AC 119 ms
40,780 KB
testcase_19 AC 121 ms
41,288 KB
testcase_20 AC 121 ms
41,152 KB
testcase_21 AC 109 ms
40,800 KB
testcase_22 AC 122 ms
41,120 KB
testcase_23 AC 119 ms
41,056 KB
testcase_24 AC 101 ms
39,872 KB
testcase_25 AC 113 ms
40,448 KB
testcase_26 AC 105 ms
40,836 KB
testcase_27 AC 111 ms
41,196 KB
testcase_28 AC 122 ms
41,360 KB
testcase_29 AC 112 ms
40,848 KB
権限があれば一括ダウンロードができます

ソースコード

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