結果

問題 No.3254 Xor, Max and Sum
ユーザー ks2m
提出日時 2025-09-05 21:49:55
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 677 bytes
コンパイル時間 3,155 ms
コンパイル使用メモリ 76,820 KB
実行使用メモリ 46,732 KB
最終ジャッジ日時 2025-09-05 21:50:11
合計ジャッジ時間 12,010 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25 WA * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

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

		if (n == 1) {
			System.out.println(0);
		} else if (n % 2 == 0) {
			System.out.println(n * m);
		} else {
			long v1 = (n - 1) * m;
//			if (Long.bitCount(m) == 1) {
//				System.out.println(v1);
//				return;
//			}
			long v2 = 1L << 30;
			v2--;
			int cnt = 0;
			for (int i = 29; i >= 0; i--) {
				if ((m >> i & 1) == 1) {
					cnt++;
					v2 -= 1L << i;
				} else if (cnt < 2) {
					v2 -= 1L << i;
				}
			}
			System.out.println(v1 + v2 * 2);
		}
	}
}
0