Cod sursa(job #2490813)

Utilizator cyber_ghSoltan Gheorghe cyber_gh Data 10 noiembrie 2019 23:01:46
Problema Aprindere Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.42 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("aprindere.in");
ofstream fout("aprindere.out");

const int MAXN = 1010;
struct Switch {
    int id, time;
    bool exists;
    vector<int> rooms;
};
int N, M;
Switch arr[MAXN];

bool isOn[MAXN];

int main() {
    fin >> N >> M;
    for (int i = 0; i < N; i++) {
        int x;
        fin >> x;
        isOn[i] = ( x == 1);
    }


    for (int i = 0; i < M; i++) {
        Switch tmp;
        tmp.exists = true;
        fin >> tmp.id >> tmp.time;
        
        int sz;
        fin >> sz;
        //cout << tmp.id << " " << tmp.time << " " << sz<< endl;
        for (int room; sz--;) {
            fin >> room;
            tmp.rooms.push_back(room);
        }
        arr[tmp.id] = tmp;
    }

    int ans = 0;

    for (int i = 0 ; i < N; i++) {
        
        if (!isOn[i]) {
            //cout << i << " " << arr[i].exists << endl;
        //    cout << i << endl;
        //    for (int i = 0; i < N; i++) cout << isOn[i] << " " ;
        //     cout << endl;
           if (arr[i].exists) {
               ans += arr[i].time;
               for (auto it: arr[i].rooms) isOn[it] = !isOn[it];
           } else {
               // no solution
               cout << "no solution";
           }
        //    cout << i << endl;
        //    for (int i = 0; i < N; i++) cout << isOn[i] << " " ;
        //    cout << endl;
        }
        
    }

    fout << ans;

    return 0;
}