結果

問題 No.3088 XOR = SUM
ユーザー wsrtrt
提出日時 2025-04-04 22:19:50
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 1,794 bytes
コンパイル時間 3,703 ms
コンパイル使用メモリ 273,872 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-04-04 22:20:20
合計ジャッジ時間 15,692 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto& i:a)
#define ff first 
#define ss second 
#define all(a) begin(a),end(a)
#define allr(a) rbegin(a),rend(a)
#define pb push_back
using namespace std;
using ll =long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
template<class T> inline bool chmin(T& a,T b){return a>b?a=b,1:0;}
template<class T> inline bool chmax(T& a,T b){return a<b?a=b,1:0;}
pll naive(ll n){
    ll res{};pll ans;
    rep(x,0,n+1){
        rep(y,0,n+1){
            if(x+y>n)continue;
            if((x^y)!=x+y)continue;
            if(chmax(res,(ll)x*y)){
                ans={x,y};
            }
        }
    }
    return ans;
}
pll solve(ll n){
    if(n==0){
        return {0,0};
    }
    int MAXLOG=62;
    pll a,b;
    {
        ll x{},y{};
        rrep(i,MAXLOG,0){
            if((n>>i)&1){
                x=(1ll<<i);
                break;
            }
        }
        y=n-x;
        a={x,y};
    }
    {
        ll x{};ll y{};
        rrep(i,MAXLOG,1){
            if((n>>i)&1){
                x=(1ll<<(i-1));
                y=((1ll<<i)-1-x);
                break;
            }
        }
        b={x,y};
    }
    if(2*a.ss>b.ss)return a;
    else return b;
}

int main(){
    cin.tie(0)->sync_with_stdio(0);
    
    int t;
    cin>>t;
    while(t--){
        ll n;cin>>n;
        pll ans=solve(n);
        cout<<ans.ff<<' '<<ans.ss<<'\n';
    }
    /*
    rep(n,0,1000){
        pll a=solve(n);pll b=naive(n);
        if(a.ff*a.ss!=b.ff*b.ss){
            cout<<n<<endl;
            cout<<a.ff<<' '<<a.ss<<endl;
            cout<<b.ff<<' '<<b.ss<<endl;
            return 0;
        }
    }*/
    return 0;
}
/*

*/
0