CCCPaste

Untitled

#include 
#include 
#include 
using namespace std;
int main() {
    int L, W;
    cin >> L >> W;
    int N;
    cin >> N;
    int b;
    cin >> b;
    vector > v;
    bool visited[L + 5][W + 5];
    for(int i = 0; i <= L; i++) {
        for(int j = 0; j <= W; j++) {
            visited[i][j] = false;
        }
    }
    for(int i = 0; i < b; i++) {
        int a, c;
        cin >> a >> c;
        v.push_back(make_pair(a, c));
        visited[a][c] = true;
    }
    
    int di[] = {-1, 1, 0, 0};
    int dj[] = {0, 0, -1, 1};
    queue > > q;
    q.push(v);
    int barokni = 0;
    int meseci = 0;
    while(!q.empty()) {
        vector > c = q.front();
        q.pop();
        barokni += c.size();
        if(barokni >= N) {
            break;
        }
        meseci++;

        vector > novi_barokni;
        for(int i = 0; i < c.size(); i++) {
            for(int j = 0; j < 4; j++) {
                int ti = c[i].first + di[j];
                int tj = c[i].second + dj[j];
                if(ti >= 1 and ti <= L and tj >= 1 and tj <= W and !visited[ti][tj]) {
                    visited[ti][tj] = true;
                    novi_barokni.push_back(make_pair(ti, tj));
                }
            }
        }
        q.push(novi_barokni);
    }
    cout << meseci << endl;
    return 0;
}

/*

 */