Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int64_t inf = 1000 * 1000 * 1000;
  6. int64_t inf64 = inf * inf;
  7. int64_t mod = 228228227;
  8. int64_t nll = 0;
  9.  
  10. #define se second
  11. #define fi first
  12.  
  13. int32_t main() {
  14. ios_base::sync_with_stdio(false);
  15. cin.tie(NULL);
  16. cout.tie(NULL);
  17. cerr << fixed << setprecision(8);
  18. srand(time(0));
  19. auto START_TIME = chrono::high_resolution_clock::now();
  20.  
  21. int32_t n;
  22. int64_t anss = 0;
  23. cin >> n;
  24. int32_t cur_active = n;
  25. map<int64_t, set<int32_t> > q, pr;
  26. set<int64_t> cur;
  27. vector<int64_t> a(n), b(n), used(n, 1);
  28. for (int32_t i = 0; i < n; ++i)
  29. cin >> a[i];
  30. for (int32_t i = 0; i < n; ++i)
  31. cin >> b[i];
  32. for (int32_t i = 0; i < n; ++i)
  33. {
  34. cur.insert(i);
  35. bitset<60> bts = a[i];
  36. for (int32_t j = 0; j < 60; ++j)
  37. {
  38. if (bts[j] == 0)
  39. {
  40. q[j].insert(i);
  41. }
  42. }
  43. }
  44. for (int32_t i = 0; i < n; ++i)
  45. {
  46. bitset<60> bts = a[i];
  47. for (int32_t j = 0; j < 60; ++j)
  48. {
  49. if (bts[j] == 1)
  50. {
  51. for (auto &c : q[j])
  52. pr[i].insert(c);
  53. }
  54. }
  55. }
  56. int32_t last_removed = -1;
  57. for (int32_t i = 0; i < n; ++i)
  58. {
  59. //cout << i << " " << pr[i].size() << " " << cur_active << endl;
  60. if (used[i] == 1 && pr[i].size() == cur_active - 1)
  61. {
  62. --cur_active;
  63. last_removed = i;
  64. used[i] = 0;
  65. for (int32_t z = 0; z < n; ++z)
  66. {
  67. if (z != i)
  68. {
  69. if (pr[z].find(i) != pr[z].end())
  70. pr[z].erase(i);
  71. }
  72. }
  73. //cout << "bad: " << i << endl;
  74. i = -1;
  75. continue;
  76. }
  77. }
  78. int32_t cnt = 0;
  79. for (int32_t i = 0; i < n; ++i)
  80. {
  81. if (used[i] == 1)
  82. {
  83. anss += b[i];
  84. ++cnt;
  85. }
  86. }
  87. if (cnt == 1)
  88. cout << 0;
  89. else
  90. cout << anss;
  91.  
  92. cerr << endl << chrono::duration<long double>(chrono::high_resolution_clock::now() - START_TIME).count() << " sec.";
  93. }
  94. /*
  95. 3
  96. -2 5
  97. 10 4
  98. 5 8
  99. 4
  100. 4 10
  101. 4 -2
  102. 5 0
  103. 5 100
  104.  
  105. 3 6
  106. 1 4
  107. 1 5
  108. 1 6
  109. 2 4
  110. 2 5
  111. 2 6
  112. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement