Submission #1364257

#TimeUsernameProblemLanguageResultExecution timeMemory
1364257jojeonghoonKirameki of Revue (KAISTRUN26SPRING_E)C++20
40 / 100
3098 ms98296 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define int ll
#define vi vector<int>
#define rep(i,s,e) for(int i=(s); i<=(e); i++)
#define arr2 array<int,2>
#define arr3 array<int,3>
using namespace std;
using namespace __gnu_pbds;

const int LM=100100, asdf=107, fdsa=1e9+7;
int N, k;
int A[LM];

int Naive(){
    vi a;
    rep(i,1,N){
        rep(j,i+1,N) a.push_back(A[i]^A[j]);
    }
    sort(a.begin(), a.end());

    return a[k-1];
}

gp_hash_table<int,int>m[31];

int Q(int M){
    int ans=0;
    rep(i,1,N){
        for(int j=30; j>=0; j--){
            if(M>>j&1){
                int q=( ( ((A[i]^M)>>j) ^ 1 ) <<j );
                ans += m[j][q];
            }
            if(m[j][( ((A[i]^M)>>j) ) <<j]  ==0) break;
        }
    }
    return (ans-N)/2;
}


signed main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin>>N>>k;
    rep(i,1,N) cin>>A[i];

    rep(i,1,N){
        rep(j,0,30){
            m[j][ ((A[i]>>j)<<j)]++;
        }
    }

    int low=0, hig=(1ll<<31)-1;

    while(low<hig){
        int mid=low+hig>>1;
        if(Q(mid) < k) low = mid+1;
        else hig=mid;
    }
    cout<<low-1;
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...