Nu aveti permisiuni pentru a descarca fisierul grader_test8.in

Cod sursa(job #1551043)

Utilizator george.stefanGeorge Stefan george.stefan Data 15 decembrie 2015 03:26:00
Problema Balanta Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.52 kb
#include <iostream>
#include <stdio.h>

const int L = 2000;

using namespace std;

int main()
{
    freopen("balanta.in", "r", stdin);
    freopen("balanta.out", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    bool valid[L];

    for(int i = 1; i < L; i ++)
        valid[i] = 1;

    int n, m, q, ban[L], x;

    cin >> n >> m;

    for(int i = 0; i < m; i ++)
    {
        cin >> q;

        for(int j = 0; j <= n; j ++)
            ban[j] = 0;

        for(int j = 0; j < q; j ++)
        {
            cin >> x;

            ban[x] = 1;
        }

        for(int j = 0; j < q; j ++)
        {
            cin >> x;

            ban[x] = 2;
        }

        cin >> x;

        if(x == 0)
        {
            for(int j = 0; j <= n; j ++)
            {
                if(ban[j])
                    valid[j] = 0;
            }
        }

        if(x == 1)
        {
            for(int j = 0; j <= n; j ++)
            {
                if(ban[j] == 2)
                    valid[j] = 0;
            }
        }

        if(x == 2)
        {
            for(int j = 0; j <= n; j ++)
            {
                if(ban[j] == 1)
                    valid[j] = 0;
            }
        }
    }

    int nr = 0, poz, i = 0;

    while(nr < 2 && i <= n)
    {
        if(valid[i])
        {
            nr ++;
            poz = i;
        }
        i ++;
    }

    if(nr == 1)
        cout << poz;
    else cout << 0;

    return 0;
}