結果
| 問題 |
No.3254 Xor, Max and Sum
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-09-05 21:40:03 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,147 bytes |
| コンパイル時間 | 1,709 ms |
| コンパイル使用メモリ | 195,000 KB |
| 実行使用メモリ | 7,720 KB |
| 最終ジャッジ日時 | 2025-09-05 21:40:08 |
| 合計ジャッジ時間 | 3,087 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 WA * 24 |
ソースコード
#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;}
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;
}
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;
}