Cod sursa(job #2200184)

Utilizator victor.ciurelCiurel Victor victor.ciurel Data 30 aprilie 2018 16:22:51
Problema Aprindere Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.99 kb
#include <cstdio>
#include <string>

using namespace std;

const int NMAX = 1000;
const string input_filename = "aprindere.in";
const string output_filename = "aprindere.out";

int read()
{
    int n, m, room, rooms[NMAX], sol = 0, i, j, switched_room, switched_rooms, tm;
    bool ok;

    FILE *f = fopen(input_filename.data(), "r");
    fscanf(f, "%d%d", &n, &m);
    for (i = 0; i < n; i++)
        fscanf(f, "%d", &rooms[i]);
    for (i = 0; i < m; i++) {
        ok = false;
        fscanf(f, "%d%d%d", &room, &tm, &switched_rooms);
        if (!rooms[room]) {
            sol += tm;
            ok = true;
        }
        for (j = 0; j < switched_rooms; j++) {
            fscanf(f, "%d", &switched_room);
            if (ok)
                rooms[switched_room] ^= 1;
        }
    }
    fclose(f);
    return sol;
}

void write(int sol)
{
    FILE *f = fopen(output_filename.data(), "w");
    fprintf(f, "%d\n", sol);
    fclose(f);
}

int main()
{
    int sol = read();
    write(sol);
    return 0;
}