結果

問題 No.126 2基のエレベータ
ユーザー YamaKasaYamaKasa
提出日時 2018-07-14 15:57:44
言語 Java21
(openjdk 21)
結果
AC  
実行時間 136 ms / 5,000 ms
コード長 707 bytes
コンパイル時間 2,092 ms
コンパイル使用メモリ 74,316 KB
実行使用メモリ 41,956 KB
最終ジャッジ日時 2024-04-19 01:52:55
合計ジャッジ時間 6,895 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
41,300 KB
testcase_01 AC 134 ms
41,648 KB
testcase_02 AC 131 ms
41,724 KB
testcase_03 AC 130 ms
41,140 KB
testcase_04 AC 128 ms
41,528 KB
testcase_05 AC 135 ms
41,596 KB
testcase_06 AC 127 ms
41,344 KB
testcase_07 AC 134 ms
41,632 KB
testcase_08 AC 128 ms
41,136 KB
testcase_09 AC 131 ms
41,400 KB
testcase_10 AC 136 ms
41,956 KB
testcase_11 AC 114 ms
40,232 KB
testcase_12 AC 128 ms
41,260 KB
testcase_13 AC 127 ms
41,528 KB
testcase_14 AC 115 ms
41,204 KB
testcase_15 AC 131 ms
41,732 KB
testcase_16 AC 123 ms
41,468 KB
testcase_17 AC 129 ms
41,760 KB
testcase_18 AC 113 ms
40,228 KB
testcase_19 AC 124 ms
41,532 KB
testcase_20 AC 130 ms
41,572 KB
testcase_21 AC 127 ms
41,128 KB
testcase_22 AC 130 ms
40,936 KB
testcase_23 AC 130 ms
41,288 KB
testcase_24 AC 129 ms
41,428 KB
testcase_25 AC 115 ms
40,316 KB
testcase_26 AC 127 ms
41,168 KB
testcase_27 AC 128 ms
41,340 KB
testcase_28 AC 127 ms
40,976 KB
testcase_29 AC 128 ms
41,284 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int A = scan.nextInt();
		int B = scan.nextInt();
		int S = scan.nextInt();
		scan.close();
		int l1 = Math.abs(S - A);
		int l2 = Math.abs(S - B);
		if(S == 1) {
			if(A == 0) {
				System.out.println(2);
			}else {
				System.out.println(A);
			}
			System.exit(0);
		}
		if(l1 <= l2) {
			int ans = l1 + S;
			System.out.println(ans);
		}else {
			int ans = l2;
			if(A == 0) {
				ans += 2 + S - 1;
				System.out.println(ans);
				System.exit(0);
			}
			int t1 = l1 + A;
			int t2 = S + Math.abs(A - 1);
			ans += Math.min(t1, t2);
			System.out.println(ans);
		}
	}
}
0