Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <range/v3/all.hpp> // get everything
- #include <absl/time/time.h>
- #include <absl/time/clock.h>
- #include <sstream>
- #include <map>
- #include <unordered_set>
- //using namespace std;
- using namespace ::ranges;
- using namespace ::ranges::views;
- int main() {
- auto start = absl::Now();
- std::unordered_multiset<std::string> lines;
- for (std::string line; std::getline(std::cin, line);) {
- if (line.empty()) break;
- lines.insert(line);
- }
- auto filter_until = [](auto lines, bool keep_most) {
- for (int i = 0; lines.size() > 1; ++i) {
- auto n = count_if(lines, [i](const auto &l) { return l[i] == '1'; });
- bool more_ones = n >= lines.size() - n;
- lines = lines | filter([i, more_ones, keep_most](const std::string &l) {
- return more_ones ^ keep_most ? l[i] == '1' : l[i] == '0';
- });
- }
- return lines;
- };
- auto ox = filter_until(lines, true);
- auto co2 = filter_until(lines, false);
- std::cout << stoi(*ox.begin(), nullptr, 2) * stoi(*co2.begin(), nullptr, 2) << std::endl;
- std::cout << absl::Now() - start << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment