結果
問題 |
No.2977 Kth Xor Pair
|
ユーザー |
![]() |
提出日時 | 2024-12-03 11:28:58 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2,093 ms / 3,000 ms |
コード長 | 703 bytes |
コンパイル時間 | 2,012 ms |
コンパイル使用メモリ | 201,404 KB |
最終ジャッジ日時 | 2025-02-26 10:46:22 |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 34 |
ソースコード
#include <bits/stdc++.h> using namespace std; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } int main() { fast_io(); int n; long long k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } k--; int ans = 0; for (int i = 30; i >= 0; i--) { map<int, long long> cnt; int msk = ~((1 << i) - 1); for (int j = 0; j < n; j++) { cnt[a[j] & msk]++; } long long cur = 0; for (auto [key, val] : cnt) { if ((key ^ ans) > key && cnt.count(key ^ ans)) { cur += val * cnt[key ^ ans]; } else if (ans == 0) { cur += val * (val - 1) / 2; } } if (cur <= k) { ans |= 1 << i; k -= cur; } } cout << ans << endl; }