結果

問題 No.2977 Kth Xor Pair
ユーザー V_Melville
提出日時 2024-12-02 05:23:28
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
AC  
実行時間 1,747 ms / 3,000 ms
コード長 828 bytes
コンパイル時間 6,303 ms
コンパイル使用メモリ 164,432 KB
実行使用メモリ 13,440 KB
最終ジャッジ日時 2024-12-02 05:24:20
合計ジャッジ時間 33,556 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;

int main() {
    cin.tie(nullptr) -> sync_with_stdio(false);
    
    int n; ll k;
    cin >> n >> k;
    --k;
    
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    
    int ans = 0;
    for (int i = 30; i >= 0; --i) {
        map<int, int> mp;
        for (int x : a) mp[x>>i<<i]++;
        
        ll cnt = 0;
        for (auto [x, num] : mp) {
            if (x > (x^ans)) continue; 
            
            if (ans == 0) cnt += (ll)num*(num-1)/2;
            else {
                if (mp.count(x^ans)) cnt += (ll)num*mp[x^ans]; 
            }
        }
        
        if (cnt <= k) {
            ans |= 1<<i;
            k -= cnt;
        }
    }
    
    cout << ans << '\n';
    
    return 0;
}
0