Cod sursa(job #1676441)

Utilizator razvandRazvan Dumitru razvand Data 5 aprilie 2016 22:08:22
Problema Arbori de intervale Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 3.11 kb
#include <iostream>
#include <fstream>
#include <vector>
#define KI Ki+sc+1

using namespace std;

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

struct ev {
    int st;
    int en;
    int t;
    int v;
};

struct mt {
    int K;
    vector<ev> evs;
};

ev temp;
mt mat[2003][2003];
pair<int,int> dir;
pair<int,int> dir2;
pair<int,int> head;
vector<ev>::iterator it;
int Ki;
int sc;
int n,m,k,evm,x,y,T,T2;
char w[2003];
int KW;
int mar;

void afis() {

    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            if(mat[i][j].K == sc+Ki)
                w[KW++] = '#';
            else if(mat[i][j].K > sc-(k-Ki))
                w[KW++] = 'O';
            else
                w[KW++] = '.';
        }
        w[KW++] = '\0';
        out << w << '\n';
        KW = 0;
    }

}

int main() {

    in >> n >> m >> k >> evm;
    Ki = k;

    for(int i = 0; i < evm; i++) {
        in >> temp.t >> x >> y >> temp.st >> temp.en;
        if(temp.t == 2) {
            in >> temp.v;
            if(temp.en > T2)
                T2 = temp.en;
        } else {
            mar++;
        }
        mat[x][y].evs.push_back(temp);
        if(temp.en > T)
            T = temp.en;
    }

    dir.first = 0;
    dir.second = 1;
    dir2 = dir;
    head.first = 1;
    head.second = k;

    for(sc = k; sc >= 1; sc--)
        mat[1][sc].K = sc;

    for(sc = 0; sc <= T; sc++) {

        for(it = mat[head.first][head.second].evs.begin(); it != mat[head.first][head.second].evs.end(); it++) {

            if((*it).st <= sc && sc < (*it).en) {

                if((*it).t == 1) {
                    k++;
                    mar--;
                    it--;
                    mat[head.first][head.second].evs.erase(it+1);
                } else {

                    if((*it).v == 1) {
                        dir.first = -1;
                        dir.second = 0;
                    }
                    if((*it).v == 2) {
                        dir.first = 0;
                        dir.second = 1;
                    }
                    if((*it).v == 3) {
                        dir.first = 1;
                        dir.second = 0;
                    }
                    if((*it).v == 4) {
                        dir.first = 0;
                        dir.second = -1;
                    }

                }

            }

        }

        if(mar == 0 && sc >= T2)
            break;
        if(sc == T)
            break;

        head.first += dir.first;
        head.second += dir.second;

        if(head.first > n)
            head.first = 1;
        if(head.first <= 0)
            head.first = n;
        if(head.second > m)
            head.second = 1;
        if(head.second <= 0)
            head.second = m;

        if(mat[head.first][head.second].K > sc+1-(k-Ki)) {

            out << "BLOCAT" << '\n';
            afis();
            return 0;

        }

        mat[head.first][head.second].K = KI;

    }

    out << "LIBER" << '\n';
    afis();

    return 0;
}