結果
| 問題 |
No.3254 Xor, Max and Sum
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-09-07 00:30:27 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,296 bytes |
| コンパイル時間 | 2,013 ms |
| コンパイル使用メモリ | 193,960 KB |
| 実行使用メモリ | 7,720 KB |
| 最終ジャッジ日時 | 2025-09-07 00:30:31 |
| 合計ジャッジ時間 | 3,715 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 WA * 23 |
コンパイルメッセージ
main.cpp: In function ‘int32_t main()’:
main.cpp:44:16: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
44 | freopen(TASKNAME ".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:45:16: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
45 | freopen(TASKNAME ".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define db double
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b / __gcd(a,b)
#define I first
#define II second
#define pb push_back
#define ii pair<int,int>
const int INF = 2 * 1e18;
const int N = 3e5 + 1;
const int MOD = 1e9 + 7;
int n, k;
void solve() {
cin >> n >> k;
if (n == 1 || k == 0) cout << 0; else
if (n % 2 == 0) cout << n * k; else {
int cnt = 0;
for (int i = 30; i >= 0; i--)
if ((k >> i) & 1) {
int x = k;
x ^= (1 << i);
int ok = 0;
for (int j = i - 1; j >= 0; j--) {
if ((k >> j) & 1) ok = 1;
if (ok) x ^= (1 << j);
}
int y = k ^ x;
// cout << x << ' ' << y << '\n';
cout << max((n - 1) * k, k * (n - 2) + x + y);
return ;
}
cout << (n - 1) * k;
}
}
int32_t main()
{
#define TASKNAME "test"
ios_base::sync_with_stdio(0);
cin.tie(0);
if (fopen(TASKNAME ".inp","r" ))
{
freopen(TASKNAME ".inp","r",stdin);
freopen(TASKNAME ".out","w",stdout);
}
int t = 1;
// cin >> t;
while (t--) solve();
return 0;
}