結果

問題 No.3254 Xor, Max and Sum
ユーザー GOTKAKO
提出日時 2025-09-05 21:49:36
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,205 bytes
コンパイル時間 2,118 ms
コンパイル使用メモリ 195,008 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-09-05 21:49:40
合計ジャッジ時間 3,882 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25 WA * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    long long N,M; cin >> N >> M;
    if(N%2 == 0){cout << N*M << endl; return 0;}
    if(N == 1){cout << 0 << endl; return 0;}
    long long answer = N/2*2*M,now = (N-2)*M;
    for(int i=30; i>=0; i--) if(M&(1<<i)){
        int mask = (1<<i)-1;
        now += (1LL<<i);
        int add = 0,left = M-(1LL<<i);
        for(int k=i-1; k>=0; k--){
            if(left&(1<<k)) add += 1<<k;
            else if(left >= (1<<k)) add += 1<<k,now += 1<<k,left -= 1<<k;
        }
        now += add;
        break;
    }
    cout << max(answer,now) << endl;
return 0;
    int maxa = -1;
    vector<int> best(N),A(N);
    auto dfs = [&](auto dfs,int pos,int low,int sum = 0) -> void {
        if(pos == N){
            if(maxa >= sum) return;
            int x = 0;
            for(auto a : A) x ^= a;
            if(x == 0) maxa = sum,best = A;
            return;
        }
        for(int i=low; i<=M; i++){
            A.at(pos) = i;
            dfs(dfs,pos+1,i,sum+i);
        }
    };
    dfs(dfs,0,0);
    cout << maxa << endl;
    for(auto a : best) cout << a << " "; cout << endl;
}
0