結果

問題 No.126 2基のエレベータ
ユーザー takeya_okinotakeya_okino
提出日時 2019-09-12 23:28:59
言語 Java21
(openjdk 21)
結果
AC  
実行時間 131 ms / 5,000 ms
コード長 646 bytes
コンパイル時間 2,183 ms
コンパイル使用メモリ 74,140 KB
実行使用メモリ 41,804 KB
最終ジャッジ日時 2024-04-19 01:54:46
合計ジャッジ時間 6,977 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
41,544 KB
testcase_01 AC 126 ms
41,444 KB
testcase_02 AC 114 ms
39,996 KB
testcase_03 AC 124 ms
41,556 KB
testcase_04 AC 128 ms
41,224 KB
testcase_05 AC 127 ms
41,600 KB
testcase_06 AC 129 ms
41,356 KB
testcase_07 AC 127 ms
41,396 KB
testcase_08 AC 130 ms
41,208 KB
testcase_09 AC 127 ms
41,480 KB
testcase_10 AC 126 ms
41,448 KB
testcase_11 AC 125 ms
41,160 KB
testcase_12 AC 129 ms
41,500 KB
testcase_13 AC 126 ms
41,144 KB
testcase_14 AC 129 ms
41,416 KB
testcase_15 AC 127 ms
41,248 KB
testcase_16 AC 131 ms
41,384 KB
testcase_17 AC 131 ms
41,564 KB
testcase_18 AC 126 ms
41,528 KB
testcase_19 AC 127 ms
41,244 KB
testcase_20 AC 126 ms
41,428 KB
testcase_21 AC 117 ms
40,384 KB
testcase_22 AC 115 ms
40,268 KB
testcase_23 AC 130 ms
41,560 KB
testcase_24 AC 127 ms
41,276 KB
testcase_25 AC 127 ms
41,276 KB
testcase_26 AC 117 ms
40,228 KB
testcase_27 AC 127 ms
41,236 KB
testcase_28 AC 127 ms
41,804 KB
testcase_29 AC 114 ms
40,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int s = sc.nextInt();
    int ans = 0;
    if(Math.abs(a - s) <= Math.abs(b - s)) {
      ans = Math.abs(a - s) + s;
    } else {
      ans = Math.abs(b - s) + Math.abs(a - s) + a;
      if(a == 0) ans++;
      if(a == 0) {
        ans = Math.min(ans, Math.abs(b - s) + Math.abs(s - 1) + 2);
      } else {
        ans = Math.min(ans, Math.abs(b - s) + Math.abs(s - 1) + a);
      }
    }
    if(s == 1) ans = Math.abs(a - s) + 1;
    System.out.println(ans);
  }
}
0