結果

問題 No.3254 Xor, Max and Sum
ユーザー nono00
提出日時 2025-09-05 22:34:34
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,260 bytes
コンパイル時間 3,107 ms
コンパイル使用メモリ 278,516 KB
実行使用メモリ 15,948 KB
最終ジャッジ日時 2025-09-05 22:34:42
合計ジャッジ時間 7,903 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other OLE * 1 -- * 47
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template <class T>
using MaxHeap = std::priority_queue<T>;
template <class T>
using MinHeap = std::priority_queue<T, vector<T>, greater<T>>;
#define rep2(i, n) for (ll i = 0; i < (n); i++)
#define rep3(i, l, r) for (ll i = (l); i < (r); i++)
#define rrep2(i, n) for (ll i = n; i-- > 0;)
#define rrep3(i, r, l) for (ll i = (r); i-- > (l);)
#define overload(a, b, c, d, ...) d
#define rep(...) overload(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define rrep(...) overload(__VA_ARGS__, rrep3, rrep2)(__VA_ARGS__)
#define all(x) begin(x), end(x)
bool chmin(auto& lhs, auto rhs) {
    return lhs > rhs ? lhs = rhs, 1 : 0;
}
bool chmax(auto& lhs, auto rhs) {
    return lhs < rhs ? lhs = rhs, 1 : 0;
}
struct IOIO {
    IOIO() {
        std::cin.tie(0)->sync_with_stdio(0);
    }
} ioio;

ll naive(ll n, ll m) {
    constexpr ll inf = -1e18;
    const ll M = bit_ceil((ull)(m + 1));
    vector<ll> dp(M, inf);
    dp[0] = 0;
    rep(i, n) {
        vector<ll> ndp(M, inf);
        rep(j, M) {
            if (dp[j] == inf) continue;
            rep(k, m + 1) {
                chmax(ndp[j ^ k], dp[j] + k);
            }
        }
        dp = std::move(ndp);
    }
    return dp[0];
}

void solve() {
    ll n, m;
    cin >> n >> m;
    //  const ll naive_ans = naive(n, m);
    ll ans = 0;
    if (n == 1) {
        ans = 0;
    } else if (n % 2 == 0) {
        ans = n * m;
    } else {
        const int LOG = 31;
        ll R = n;
        ll L = 0;
        rrep(i, LOG) {
            ll w = 1LL << i;
            if (m & w) {
                ans += w * 2 * (n / 2);
                if (R) R--, L++;
            } else {
                ans += w * 2 * (L / 2);
            }
        }
        //  ans = (n - 3) * m;
        //  int w = bit_width((ull)m);
        //  ans += 2 * (1LL << (w - 1));
        //  w = bit_width((ull)(m - (1LL << (w - 1))));
        //  if (w != 0) {
        //      ans += 2 * ((1LL << w) - 1);
        //  }
    }
    cout << ans << '\n';
    //  cerr << "[INPUT] " << n << ' ' << m << endl;
    //  cerr << naive_ans << ' ' << ans << endl;
}

int main() {
    int t = 1;
    cin >> t;
    while (t--) solve();
}
0