結果

問題 No.3088 XOR = SUM
ユーザー NortGlG
提出日時 2025-04-20 15:03:44
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 789 bytes
コンパイル時間 2,019 ms
コンパイル使用メモリ 191,796 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-04-20 15:04:01
合計ジャッジ時間 16,120 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

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

void solve() {
    ll n;
    cin >> n;
    if (__builtin_popcountll(n) == 0) {
        cout << "0 0\n";
        return;
    }
    if (__builtin_popcountll(n) == 1) {
        ll msb = (1ll << (63 - __builtin_clzll(n)));
        if (msb == 1) cout << "0 0\n";
        else cout << (msb >> 1) << ' ' << (msb >> 1) - 1 << '\n';
        return;
    }
    ll msb = (1ll << (63 - __builtin_clzll(n)));
    ll nsb = (1ll << (63 - __builtin_clzll(n ^ msb)));
    if ((nsb << 2) >= msb) cout << msb << ' ' << n - msb << '\n';
    else cout << (msb >> 1) << ' ' << (msb >> 1) - 1 << '\n';
}

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int q;
    cin >> q;
    while (q--) {
        solve();
    }
    return 0;
}
0