結果

問題 No.3254 Xor, Max and Sum
ユーザー ルビサファせだい
提出日時 2025-09-05 22:29:54
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,255 bytes
コンパイル時間 1,984 ms
コンパイル使用メモリ 199,440 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-09-05 22:29:58
合計ジャッジ時間 3,432 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24 WA * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/fenwicktree.hpp>
#include <atcoder/segtree.hpp>
#include <atcoder/modint.hpp>
#include <atcoder/dsu.hpp>
#include <atcoder/lazysegtree.hpp>

using namespace atcoder;
using namespace std;
using ll = long long;
using ull = unsigned long long;
template <class T>
using max_heap = priority_queue<T>;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<>>;
ll ll_min = numeric_limits<ll>::min();
ll ll_max = numeric_limits<ll>::max();
ll ALPHABET_N = 26;
using mint = modint998244353;
#define rep(i, n) for (ll i = (ll)0; i < (ll)n; i++)
#define rep_(i, k, n) for (ll i = (ll)k; i < (ll)n; i++)
#define all(a) a.begin(), a.end()

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n, m;
	cin >> n >> m;
	if (n % 2 == 0)
	{
		cout << m * n << endl;
	}
	else
	{
		n -= 2;
		ll ans = m * n;
		ll mx_bit = 0;
		while ((1LL << mx_bit) <= m)
			mx_bit++;
		ll a = 0;
		ll b = 0;
		for (ll bt = mx_bit - 1; bt >= 0; bt--)
		{
			if(m & (1LL << bt)) {
				if(a <= b) a += (1LL << bt);
				else b += (1LL << bt);
			} else {
				ll plus = (1LL << bt);
				if(a + plus <= m && b + plus <= m) {
					a += plus;
					b += plus;
				}
			}
		}
		ans += a + b;
		cout << ans << endl;
	}
	return 0;
}
0