結果

問題 No.521 Cheeses and a Mousetrap(チーズとネズミ捕り)
ユーザー matsuyoshi30matsuyoshi30
提出日時 2018-09-27 01:43:11
言語 Java21
(openjdk 21)
結果
AC  
実行時間 140 ms / 2,000 ms
コード長 492 bytes
コンパイル時間 2,489 ms
コンパイル使用メモリ 73,760 KB
実行使用メモリ 41,568 KB
最終ジャッジ日時 2024-04-20 09:00:19
合計ジャッジ時間 7,371 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 136 ms
41,464 KB
testcase_01 AC 134 ms
41,184 KB
testcase_02 AC 138 ms
41,444 KB
testcase_03 AC 139 ms
41,348 KB
testcase_04 AC 140 ms
41,336 KB
testcase_05 AC 138 ms
41,360 KB
testcase_06 AC 122 ms
39,808 KB
testcase_07 AC 135 ms
41,196 KB
testcase_08 AC 121 ms
39,944 KB
testcase_09 AC 133 ms
41,392 KB
testcase_10 AC 135 ms
41,284 KB
testcase_11 AC 134 ms
41,268 KB
testcase_12 AC 132 ms
41,048 KB
testcase_13 AC 135 ms
41,360 KB
testcase_14 AC 137 ms
41,568 KB
testcase_15 AC 137 ms
41,488 KB
testcase_16 AC 137 ms
41,328 KB
testcase_17 AC 136 ms
41,472 KB
testcase_18 AC 135 ms
41,348 KB
testcase_19 AC 134 ms
41,332 KB
testcase_20 AC 139 ms
41,320 KB
testcase_21 AC 134 ms
41,508 KB
testcase_22 AC 126 ms
40,344 KB
testcase_23 AC 135 ms
41,196 KB
testcase_24 AC 137 ms
40,948 KB
testcase_25 AC 137 ms
41,064 KB
testcase_26 AC 137 ms
41,056 KB
testcase_27 AC 133 ms
41,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long n = in.nextLong();
        long k = in.nextLong();

        long ans = 0;
        if(!(k == 0 || k > n )) {
            long mid = (n+1) / 2;
            if(mid != k) ans = n - 2;
            else if(mid == k) {
                if(n % 2 == 0) ans = n - 2;
                else ans = n - 1;
            }
        }

        System.out.println(ans);
    }
}
0