Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <queue>
- using namespace std;
- int main() {
- int L, W;
- cin >> L >> W;
- int N;
- cin >> N;
- int b;
- cin >> b;
- vector<pair<int, int> > 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<vector<pair<int, int> > > q;
- q.push(v);
- int barokni = 0;
- int meseci = 0;
- while(!q.empty()) {
- vector<pair<int, int> > c = q.front();
- q.pop();
- barokni += c.size();
- if(barokni >= N) {
- break;
- }
- meseci++;
- vector<pair<int, int> > 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;
- }
- /*
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement