Cod sursa(job #1629372)

Utilizator PraetorGrigorosoaia Florin Praetor Data 4 martie 2016 15:00:50
Problema Aprindere Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.35 kb
#include<fstream>
#define MNOR 1002 // maximum number of rooms

using namespace std;

FILE*in;
ofstream out("aprindere.out");

int nr_of_rooms;
int nr_of_switches;
int room[MNOR]; // room[i]=0 - dark in room i
int time_to_switch[MNOR]; // time_to_switch[i]=0 if there is no switch
int nr_of_rooms_to_switch[MNOR];
int room_to_switch[MNOR][MNOR];
int r; // a room
long int minimum_time;

void read()
{
    in=fopen("aprindere.in", "r");

    fscanf(in, "%d%d", &nr_of_rooms, &nr_of_switches);
    for (int i=0; i<nr_of_rooms; i++)
        fscanf(in, "%d", &room[i]);
    for (int i=1; i<=nr_of_switches; i++)
    {
        fscanf(in, "%d", &r); // where the switch is
        fscanf(in, "%d", &time_to_switch[r]);
        fscanf(in, "%d", &nr_of_rooms_to_switch[r]);
        for (int j=1; j<=nr_of_rooms_to_switch[r]; j++)
            fscanf(in, "%d", &room_to_switch[j][r]);
    }
}

void find_minimum_time()
{
    for (int i=0; i<nr_of_rooms; i++)
        if (!room[i]) // if it's dark here
        {
            minimum_time+=time_to_switch[i];

            for (int j=1; j<=nr_of_rooms_to_switch[i]; j++)
                room[room_to_switch[j][i]]=1-room[room_to_switch[j][i]]; // switch
        }
}

void show()
{
    out<<minimum_time;
}

int main()
{
    read();
    find_minimum_time();
    show();

    return 0;
}