結果

問題 No.3254 Xor, Max and Sum
ユーザー Gia Quyết
提出日時 2025-09-05 22:07:40
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,286 bytes
コンパイル時間 1,887 ms
コンパイル使用メモリ 195,124 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-09-05 22:07:45
合計ジャッジ時間 3,360 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21 WA * 27
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int32_t main()’:
main.cpp:43:16: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   43 |         freopen(TASKNAME ".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
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 ".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#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 << '\n';
    if (n % 2 == 0) cout << n * k << '\n'; else {
        int cnt = 0;
        for (int i = 30; i >= 1; i--)
            if ((k >> i) & 1) {
                cnt++;
                if (cnt == 1) continue;
                int x = k;
                x ^= (1 << i);
                for (int j = i - 1; j >= 0; j--)
                    if (!((x >> j) & 1)) x ^= (1 << j);
                // cout << i << ' ' << x << '\n';
                int y = k ^ x;
                cout << k * (n - 2) + x + y << '\n';
                return ;
            }
        cout << (n - 1) * k << '\n';
    }
}
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;
}
0