結果

問題 No.126 2基のエレベータ
ユーザー YamaKasaYamaKasa
提出日時 2018-07-14 15:56:12
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 646 bytes
コンパイル時間 1,903 ms
コンパイル使用メモリ 74,780 KB
実行使用メモリ 53,192 KB
最終ジャッジ日時 2024-04-18 12:03:44
合計ジャッジ時間 6,399 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
40,312 KB
testcase_01 AC 119 ms
41,692 KB
testcase_02 AC 126 ms
41,532 KB
testcase_03 AC 111 ms
41,608 KB
testcase_04 AC 127 ms
41,584 KB
testcase_05 WA -
testcase_06 AC 122 ms
40,180 KB
testcase_07 AC 128 ms
41,812 KB
testcase_08 AC 111 ms
41,200 KB
testcase_09 AC 118 ms
41,048 KB
testcase_10 AC 110 ms
41,620 KB
testcase_11 AC 123 ms
41,200 KB
testcase_12 AC 108 ms
41,344 KB
testcase_13 AC 127 ms
41,596 KB
testcase_14 AC 120 ms
41,492 KB
testcase_15 AC 126 ms
41,344 KB
testcase_16 AC 102 ms
41,468 KB
testcase_17 AC 121 ms
41,408 KB
testcase_18 AC 124 ms
41,356 KB
testcase_19 AC 134 ms
41,712 KB
testcase_20 AC 114 ms
41,180 KB
testcase_21 AC 110 ms
41,824 KB
testcase_22 AC 120 ms
41,104 KB
testcase_23 AC 117 ms
41,372 KB
testcase_24 AC 122 ms
41,196 KB
testcase_25 AC 119 ms
41,360 KB
testcase_26 AC 116 ms
41,520 KB
testcase_27 AC 124 ms
41,228 KB
testcase_28 AC 123 ms
41,368 KB
testcase_29 AC 104 ms
41,264 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) {
			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