Cod sursa(job #2737640)

Utilizator redstonegamer22Andrei Ion redstonegamer22 Data 4 aprilie 2021 22:39:21
Problema Balanta Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.42 kb
#include <bits/stdc++.h>

using namespace std;

#ifndef LOCAL

ifstream in("balanta.in");
ofstream out("balanta.out");

#define cin in
#define cout out

#endif //LOCAL

const int NMAX = 16; //1024 + 16;
bitset<NMAX> possible[2];

int main()
{
    int n, m; cin >> n >> m;
    for(int i = 1; i <= n; i++)
    {
        possible[0][i] = 1;
        possible[1][i] = 1;
    }

    for(int i = 0; i < m; i++)
    {
        int k; cin >> k;
        vector<int> l(k), r(k);
        for(auto& e : l) cin >> e;
        for(auto& e : r) cin >> e;
        int q; cin >> q;

        if(q == 0)
        {
            bitset<NMAX> cntMask;
            for(auto e : l)
                cntMask[e] = 1;
            for(auto e : r)
                cntMask[e] = 1;

            cntMask = ~cntMask;
            possible[0] &= cntMask;
            possible[1] &= cntMask;
        }
        if(q == 1)
        {
            bitset<NMAX> cntMask0;
            for(auto e : l)
                cntMask0[e] = 1;

            bitset<NMAX> cntMask1;
            for(auto e : r)
                cntMask1[e] = 1;
        
            possible[0] &= cntMask0;
            possible[1] &= cntMask1;
        }
        if(q == 2)
        {
            bitset<NMAX> cntMask0;
            for(auto e : r)
                cntMask0[e] = 1;

            bitset<NMAX> cntMask1;
            for(auto e : l)
                cntMask1[e] = 1;

            possible[0] &= cntMask0;
            possible[1] &= cntMask1;
        }
    }

    #ifdef LOCAL
    for(int i = 1; i <= n; i++)
    {
        if(possible[0][i]) cout << "A" << i << endl;
        if(possible[1][i]) cout << "B" << i << endl;
    }
    #endif //LOCAL

    if(possible[0].count() > 1 || possible[1].count() > 1)
    {
        cout << 0 << endl;
        return 0;
    }

    if(possible[0].count() == 1 && possible[1].count() == 1)
    {
        bitset<NMAX> both = possible[0] & possible[1];
        if(both.count() == 0)
        {
            cout << 0 << endl;
            return 0;
        }
        else
        {
            for(int i = 1; i <= n; i++)
                if(both[i] == 1)
                    cout << i << endl;
            return 0;
        }
    }

    if(possible[0].count() == 1 || possible[1].count() == 1)
    {
        bitset<NMAX> both = possible[0] | possible[1];
        for(int i = 1; i <= n; i++)
            if(both[i] == 1)
                cout << i << endl;
        return 0;
    }

    cout << 0 << endl;
    return 0;
}