From 1795db7656d00656caddfea2e2e54e276f3e6f8a Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Mon, 6 Jun 2022 10:25:39 +0800 Subject: [PATCH] =?UTF-8?q?P4570=20[BJWC2011]=E5=85=83=E7=B4=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.luogu.com.cn/record/77009664 --- Luogu/P4570/P4570.cpp | 52 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Luogu/P4570/P4570.cpp diff --git a/Luogu/P4570/P4570.cpp b/Luogu/P4570/P4570.cpp new file mode 100644 index 00000000..12142781 --- /dev/null +++ b/Luogu/P4570/P4570.cpp @@ -0,0 +1,52 @@ +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1005; + +int n, ans; +std::pair a[N]; +unsigned long long p[N]; + +inline bool insert(unsigned long long x) { + for (int i = 0; i <= 61; i++) { + if (x & (1ull << i)) { + if (p[i]) { + x ^= p[i]; + } else { + p[i] = x; + + return true; + } + } + } + + return false; +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n; + + for (int i = 1; i <= n; i++) { + cin >> a[i].second >> a[i].first; + } + + std::sort(a + 1, a + 1 + n, std::greater>()); + + for (int i = 1; i <= n; i++) { + if (insert(a[i].second)) { + ans += a[i].first; + } + } + + cout << ans << endl; + + return 0; +}