結果

問題 No.3254 Xor, Max and Sum
ユーザー Iroha_3856
提出日時 2025-09-05 04:07:30
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 397 bytes
コンパイル時間 3,235 ms
コンパイル使用メモリ 275,780 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-09-05 05:31:40
合計ジャッジ時間 4,564 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 48
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
	int N, M; cin >> N >> M;
	
	if (N%2 == 0) {
		cout << (long long) N * M << endl;
		return 0;
	}
	
	int c = 0;
	long long ans = 0;
	for (int b = 29; b >= 0; b--) {
		if (M>>b&1) {
			ans += (N-1) * (1LL << b);
			if (c < N) {
				c++;
			}
		}
		else {
			int use = c / 2 * 2;
			ans += use * (1LL << b);
		}
	}
	
	cout << ans << endl;
}
0