結果

問題 No.521 Cheeses and a Mousetrap(チーズとネズミ捕り)
コンテスト
ユーザー kitamoto0407
提出日時 2026-03-08 11:14:36
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 999 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,201 ms
コンパイル使用メモリ 85,196 KB
実行使用メモリ 45,744 KB
最終ジャッジ日時 2026-03-08 11:14:42
合計ジャッジ時間 5,133 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.io.*;
import java.util.*;
import java.util.stream.*;

// 処理
class Process {
    private int N;
    private int K;

    Process(int N, int K) {
        this.N = N;
        this.K = K;
    }

    int getResult() {
        if((K == 0) || (K > N)) {
            return 0;
        }

        if(N % 2 == 0) {
            return (N - 2);
        }

        return ((K == ((N + 1) / 2)) ? (N - 1) : (N - 2));
    }
}

public class Main {
    public static void main(String[] args) throws IOException {
        var bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        var printWriter    = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

        // 入力
        int[] input = Stream.of(bufferedReader.readLine().trim().split("[ ]+")).mapToInt(Integer::parseInt).toArray();

        // 出力
        printWriter.println((new Process(input[0], input[1])).getResult());

        bufferedReader.close();
        printWriter.close();
    }
}
0