Cod sursa(job #2189475)

Utilizator theo2003Theodor Negrescu theo2003 Data 28 martie 2018 13:38:52
Problema Aprindere Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.93 kb
#include <fstream>
#include <vector>

using namespace std;

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

vector<char> rooms;
vector<pair<vector<int>, int> > switches;
int size, time, switchnr;

int main(){
    in>>size>>switchnr;
    rooms.resize(size);
    switches.resize(size);
    for(int x = 0;x<size;x++){
        in>>rooms[x];
        rooms[x]-='0';
    }
    for(int x = 0, room, amount, aa;x<switchnr;x++){
        in>>room>>aa>>amount;
        switches[room].first.resize(amount);
        switches[room].second = aa;
        for(int y = 0;y<amount;y++){
            in>>switches[room].first[y];
        }
    }
    for(int x = 0;x<size;x++){
        if(!rooms[x]){
            for(int y = 0;y<switches[x].first.size();y++){
                rooms[switches[x].first[y]] = rooms[switches[x].first[y]] ? 0 : 1;
            }
            time+=switches[x].second;
        }
    }
    out<<time;
}