Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int64_t inf = 1000 * 1000 * 1000;
- int64_t inf64 = inf * inf;
- int64_t mod = 228228227;
- int64_t nll = 0;
- #define se second
- #define fi first
- int32_t main() {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- cout.tie(NULL);
- cerr << fixed << setprecision(8);
- srand(time(0));
- auto START_TIME = chrono::high_resolution_clock::now();
- int32_t n;
- int64_t anss = 0;
- cin >> n;
- int32_t cur_active = n;
- map<int64_t, set<int32_t> > q, pr;
- set<int64_t> cur;
- vector<int64_t> a(n), b(n), used(n, 1);
- for (int32_t i = 0; i < n; ++i)
- cin >> a[i];
- for (int32_t i = 0; i < n; ++i)
- cin >> b[i];
- for (int32_t i = 0; i < n; ++i)
- {
- cur.insert(i);
- bitset<60> bts = a[i];
- for (int32_t j = 0; j < 60; ++j)
- {
- if (bts[j] == 0)
- {
- q[j].insert(i);
- }
- }
- }
- for (int32_t i = 0; i < n; ++i)
- {
- bitset<60> bts = a[i];
- for (int32_t j = 0; j < 60; ++j)
- {
- if (bts[j] == 1)
- {
- for (auto &c : q[j])
- pr[i].insert(c);
- }
- }
- }
- int32_t last_removed = -1;
- for (int32_t i = 0; i < n; ++i)
- {
- //cout << i << " " << pr[i].size() << " " << cur_active << endl;
- if (used[i] == 1 && pr[i].size() == cur_active - 1)
- {
- --cur_active;
- last_removed = i;
- used[i] = 0;
- for (int32_t z = 0; z < n; ++z)
- {
- if (z != i)
- {
- if (pr[z].find(i) != pr[z].end())
- pr[z].erase(i);
- }
- }
- //cout << "bad: " << i << endl;
- i = -1;
- continue;
- }
- }
- int32_t cnt = 0;
- for (int32_t i = 0; i < n; ++i)
- {
- if (used[i] == 1)
- {
- anss += b[i];
- ++cnt;
- }
- }
- if (cnt == 1)
- cout << 0;
- else
- cout << anss;
- cerr << endl << chrono::duration<long double>(chrono::high_resolution_clock::now() - START_TIME).count() << " sec.";
- }
- /*
- 3
- -2 5
- 10 4
- 5 8
- 4
- 4 10
- 4 -2
- 5 0
- 5 100
- 3 6
- 1 4
- 1 5
- 1 6
- 2 4
- 2 5
- 2 6
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement