Cod sursa(job #2585179)

Utilizator un_fes_galbendaniel guba un_fes_galben Data 18 martie 2020 18:48:48
Problema Balanta Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.72 kb
#include <fstream>
#include <bitset>
using namespace std;
bitset<1025>result;
bitset<1025>result1;
bitset<1025>left1;
bitset<1025>right1;
int v[1025],v1[1025];
int main()
{
    ifstream cin("balanta.in");
    ofstream cout("balanta.out");
    for(int i=1;i<=1024;i++)
    {
        result[i]=0;
        result1[i]=0;
    }
    int n,k,l,comp,a,ok=0;
    cin>>n>>k;
     for(int i=1;i<=n;i++)
    {
        result[i]=1;
        result1[i]=1;
    }
    for(int i=0;i<k;i++)
    {
       cin>>l;
       for(int j=0;j<l;j++)
       {
           cin>>a;
           v[j]=a;
       }
       for(int j=0;j<l;j++)
       {
           cin>>a;
           v1[j]=a;
       }
       cin>>comp;
       if(comp==1)
       {
           for(int j=0;j<l;j++)
           {
               result[v1[j]]=0;
               result1[v[j]]=0;
           }
       }
       else if(comp==2)
       {
           for(int j=0;j<l;j++)
           {
               result[v[j]]=0;
               result1[v1[j]]=0;
           }

       }
       else if(comp==0)
       {
           for(int j=0;j<l;j++)
           {
               result[v[j]]=0;
               result1[v[j]]=0;
           }
           for(int j=0;j<l;j++)
           {
               result[v1[j]]=0;
               result1[v1[j]]=0;
           }
           int cnt1=0,cnt2=0;
           for(int j=0;j<l;j++)
           {
               if(result[v[j]]==1)
               {
                   cnt1++;
               }
               if(result1[v[j]]==1)
               {
                   cnt2++;
               }
           }
           for(int j=0;j<l;j++)
           {
               if(result[v1[j]]==1)
               {
                   cnt1++;
               }
               if(result1[v1[j]]==1)
               {
                   cnt2++;
               }
           }
           if(cnt1==1)
           {
               ok=1;
               break;
           }
           else if(cnt2==1)
           {
               ok=2;
               break;
           }
       }
       if(result.count()==1)
       {
           ok=1;
           break;
       }
       else if(result1.count()==1)
       {
           ok=2;
           break;
       }
    }
    if(ok==0)
    {
        cout<<"0"<<endl;
    }
    else if(ok==1)
    {
        for(int i=1;i<=n;i++)
        {
            if(result[i]==1)
            {
                cout<<i<<endl;
                break;
            }
        }
    }
    else if(ok==2)
    {
        for(int i=1;i<=n;i++)
        {
            if(result1[i]==1)
            {
                cout<<i<<endl;
                break;
            }
        }
    }
    return 0;
}