Cod sursa(job #1070521)

Utilizator Teodor94Teodor Plop Teodor94 Data 1 ianuarie 2014 14:27:26
Problema Aprindere Scor 100
Compilator cpp Status done
Runda Teme Pregatire ACM Unibuc 2013 Marime 1.18 kb
#include <cstdio>

#define MAX_N 1000
#define MAX_LIGHTS 100

int stage[MAX_N], time[MAX_N], nr_rooms[MAX_N];
int light[MAX_N][MAX_LIGHTS];

void read( FILE *fin, int &n ) {
    int m;
    fscanf( fin, "%d%d", &n, &m );

    for ( int i = 0; i < n; ++i )
        fscanf( fin, "%d", &stage[i] );

    while ( m ) {
        int room;
        fscanf( fin, "%d", &room );
        fscanf( fin, "%d", &time[room] );
        fscanf( fin, "%d", &nr_rooms[room] );
        for ( int j = 0; j < nr_rooms[room]; ++j )
            fscanf( fin, "%d", &light[room][j] );

        --m;
    }
}

void action( int room ) {
    for ( int j = 0; j < nr_rooms[room]; ++j ) {
        ++stage[light[room][j]];
        stage[light[room][j]] &= 1;
    }
}

int solve( int n ) {
    int ans = 0;
    for ( int i = 0; i < n; ++i )
        if ( !stage[i] ) {
            ans += time[i];

            action( i );
        }
    return ans;
}

int main() {
    FILE *fin, *fout;

    fin = fopen( "aprindere.in", "r" );
    int n;
    read( fin, n );
    fclose( fin );

    fout = fopen( "aprindere.out", "w" );
    fprintf( fout, "%d\n", solve( n ) );
    fclose( fout );
}