Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <cmath>
- #include <vector>
- #include <string>
- #include <stack>
- #include <queue>
- using namespace std;
- int meseci, l, w, b;
- bool mat[3000][3000];
- void BFS(int a, int b, int c)
- {
- queue<int> redx, redy, mes;
- redx.push(a);
- redy.push(b);
- mes.push(c);
- while(!redx.empty())
- {
- int mesec = mes.front();
- mes.pop();
- int m = redx.front();
- int n = redy.front();
- redx.pop();
- redy.pop();
- if(mat[m][n+1]!= true and n+1<w and mesec+1<=meseci) { redx.push(m); redy.push(n+1); mat[m][n+1] = true; mes.push(mesec+1);}
- if(mat[m+1][n+1]!= true and n+1<w and m+1<l and mesec+1<=meseci) { redx.push(m+1); redy.push(n+1); mat[m+1][n+1] = true; mes.push(mesec+1);}
- if(mat[m+1][n]!= true and m+1<l and mesec+1<=meseci) { redx.push(m+1); redy.push(n); mat[m+1][n] = true; mes.push(mesec+1);}
- if(mat[m-1][n-1]!= true and n-1>=0 and m-1>=0 and mesec+1<=meseci){ redx.push(m-1); redy.push(n-1); mat[m-1][n-1] = true; mes.push(mesec+1);}
- if(mat[m-1][n]!= true and m-1>=0 and mesec+1<=meseci) { redx.push(m-1); redy.push(n); mat[m-1][n] = true; mes.push(mesec+1);}
- if(mat[m-1][n+1]!= true and n+1<w and m-1>=0 and mesec+1<=meseci) { redx.push(m-1); redy.push(n+1); mat[m-1][n+1] = true; mes.push(mesec+1);}
- if(mat[m][n-1]!= true and n-1>=0 and mesec+1<=meseci) { redx.push(m); redy.push(n-1); mat[m][n-1] = true; mes.push(mesec+1);}
- if(mat[m+1][n-1]!= true and n-1>=0 and m+1<l and mesec+1<=meseci) { redx.push(m+1); redy.push(n-1); mat[m+1][n-1] = true; mes.push(mesec+1);}
- }
- }
- int main()
- {
- ios::sync_with_stdio(false);
- int i, j, k, x, y, ri, ci, coutie=0;
- cin >> l >> w >> meseci >> b;
- for(i=0; i<b; i++)
- {
- cin >> ri >> ci;
- mat[ri-1][ci-1] = true;
- BFS(ri-1, ci-1, 0);
- }
- for(i=0; i<l; i++)
- for(j=0; j<w; j++)
- if(mat[i][j] == true)coutie++;
- cout << coutie;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment