Submission #558672

#TimeUsernameProblemLanguageResultExecution timeMemory
558672OlympiaBitwise (BOI06_bitwise)C++17
25 / 100
1 ms304 KiB
#include <iostream> #include <vector> #include <cmath> using namespace std; bool canDo (vector<pair<int,int> > v, int x) { if (x == 0) { return true; } for (auto& p: v) { while (p.first != 0 && (int)log2(p.first) == log2(p.second)) { int bit = log2(p.first); p.first -= (1 << bit), p.second -= (1 << bit); if (x & (1 << bit)) { x ^= (1 << bit); } } } for (auto& p: v) { if (p.second != 0 && (1 << (int)log2(p.second)) > x) { return true; } } int cntr = 0; for (auto& p: v) { if (p.second != 0) cntr += ((1 << (int)log2(p.second)) == (1 << (int)log2(x))); } if (cntr >= 2) { return true; } for (auto& p: v) { if (p.second != 0 && (int)log2(p.second) == (int)log2(x)) { int bt = log2(p.second); p.first = 0; p.second -= (1 << bt); x -= (1 << bt); return canDo(v, x); } } return false; } bool canDo (vector<vector<pair<int,int>>> vec, int x) { for (auto& v: vec) { if (!canDo(v, x)) { return false; } } return true; } int find_best (vector<vector<pair<int,int>>> vec) { int tot = 0; for (int i = 30; i >= 0; i--) { if (canDo(vec, tot + (1 << i))) { tot += (1 << i); } } return tot; } int main() { int n, m; cin >> n >> m; int tot[m]; for (int i = 0; i < m; i++) { cin >> tot[i]; } vector<vector<pair<int,int>>> vec; int ind = 0; for (int i = 0; i < m; i++) { vec.emplace_back(); while (tot[i]--) { pair<int,int> p; cin >> p.first >> p.second; vec.back().push_back(p); } } cout << find_best(vec) << '\n'; return 0; for (int i = 0; i < vec.size(); i++) { for (auto& p: vec[i]) { cout << p.first << " " << p.second << " | "; } cout << '\n'; } }

Compilation message (stderr)

bitwise.cpp: In function 'int main()':
bitwise.cpp:81:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |     for (int i = 0; i < vec.size(); i++) {
      |                     ~~^~~~~~~~~~~~
bitwise.cpp:70:9: warning: unused variable 'ind' [-Wunused-variable]
   70 |     int ind = 0;
      |         ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...