Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- #include <vector>
- #include <map>
- using namespace std;
- int main() {
- int L, W;
- cin >> L >> W;
- int barok_req;
- cin >> barok_req;
- int n;
- cin >> n;
- vector<pair<int, int>> v;
- vector<vector<bool>> visited(L, vector<bool>(W, false));
- for(int i = 0; i < n; i++) {
- int x, y;
- cin >> x >> y;
- x--; y--;
- v.push_back(make_pair(x, y));
- visited[x][y] = true;
- }
- queue<vector<pair<int, int>>> q;
- q.push(v);
- queue<int> q_mesec;
- q_mesec.push(n);
- q_mesec.push(0);
- int di[] = {-1, 1, 0, 0};
- int dj[] = {0, 0, -1, 1};
- while(!q.empty()) {
- vector<pair<int, int>> c = q.front();
- q.pop();
- int req = q_mesec.front();
- q_mesec.pop();
- int mesec = q_mesec.front();
- q_mesec.pop();
- if(req >= barok_req) {
- cout << mesec << endl;
- return 0;
- }
- vector<pair<int, int>> t;
- for(int i = 0; i < c.size(); i++) {
- for(int k = 0; k < 4; k++) {
- int ti = c[i].first + di[k];
- int tj = c[i].second + dj[k];
- if(ti >= 0 and ti < L and tj >= 0 and tj < W and !visited[ti][tj]) {
- t.push_back(make_pair(ti, tj));
- visited[ti][tj] = true;
- }
- }
- }
- q.push(t);
- q_mesec.push(req + t.size());
- q_mesec.push(mesec + 1);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement