結果

問題 No.2977 Kth Xor Pair
コンテスト
ユーザー askr58
提出日時 2024-12-02 18:06:26
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
TLE  
実行時間 -
コード長 699 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 6,506 ms
コンパイル使用メモリ 380,688 KB
実行使用メモリ 348,160 KB
最終ジャッジ日時 2026-05-24 15:25:23
合計ジャッジ時間 10,347 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 5 TLE * 1 -- * 28
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
random_device seed;
mt19937 rnd(seed());

int main()
{
    ll n,k;
    cin>>n>>k;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    vector<map<int,int>> dicts(30);
    for(int i=0;i<n;i++){
        for(int j=0;j<30;j++)dicts[j][(a[i]>>j)]+=1;
    }
    int l=-1,r=(1<<30)-1;
    while(l+1<r){
        int c=(l+r)/2;
        ll cnt=-n;
        for(int i=0;i<n;i++){
            for(int j=0;j<30;j++){
                if(c>>j&1)cnt+=dicts[j][(c>>j)^(a[i]>>j)^1];
            }
        }
        if(cnt/2>=k)r=c;
        else l=c;
    }
    cout<<l<<endl;

    
    return 0;
}
0