답안 #558672

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
558672 2022-05-08T03:54:02 Z Olympia Bitwise (BOI06_bitwise) C++17
25 / 100
1 ms 304 KB
#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

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;
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 256 KB Output isn't correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Incorrect 1 ms 212 KB Output isn't correct
6 Incorrect 1 ms 300 KB Output isn't correct
7 Incorrect 1 ms 212 KB Output isn't correct
8 Correct 1 ms 212 KB Output is correct
9 Incorrect 1 ms 212 KB Output isn't correct
10 Correct 1 ms 300 KB Output is correct
11 Incorrect 1 ms 212 KB Output isn't correct
12 Correct 1 ms 212 KB Output is correct
13 Incorrect 1 ms 212 KB Output isn't correct
14 Incorrect 1 ms 212 KB Output isn't correct
15 Incorrect 1 ms 212 KB Output isn't correct
16 Correct 1 ms 212 KB Output is correct
17 Incorrect 1 ms 296 KB Output isn't correct
18 Incorrect 1 ms 212 KB Output isn't correct
19 Incorrect 1 ms 304 KB Output isn't correct
20 Incorrect 1 ms 300 KB Output isn't correct