結果

問題 No.1052 電子機器X
ユーザー ks2m
提出日時 2020-05-15 21:50:00
言語 Java
(openjdk 23)
結果
AC  
実行時間 122 ms / 1,000 ms
コード長 434 bytes
コンパイル時間 1,986 ms
コンパイル使用メモリ 75,416 KB
実行使用メモリ 41,412 KB
最終ジャッジ日時 2024-09-19 09:28:32
合計ジャッジ時間 4,827 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		sc.close();

		if (n % 2 == 0) {
			int ans = n / 2;
			int k1 = 1 + k;
			int k2 = n + 1 - k;
			if (k1 < k2) {
				ans -= (k2 - k1) / 2 - 1;
			}
			System.out.println(ans);
		} else {
			System.out.println(Math.min(n, k + 1));
		}
	}
}
0