Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define in f
- #define out cout
- ifstream f ("a.in");
- ofstream g("tsunami.out");
- queue<pair<int, int>> q;
- int viz[200][200];
- int n;
- int m;
- int M[200][200];
- int h;
- int node;
- int rez;
- bool check(int i, int j)
- {
- if(i < 1 || j < 1 || i > n || j > m)
- return false;
- if(viz[i][j] == true)
- {
- return false;
- }
- else
- {
- if(M[i][j] > 0)
- {
- if(M[i][j] < h)
- return true;
- else return false;
- }
- return true;
- }
- }
- int main() {
- in >> n;
- in >> m;
- in >> h;
- for(int i = 1; i <= n; i++) {
- for(int j = 1; j <= m; j++) {
- in >> M[i][j];
- if(M[i][j] == 0) {
- q.push({i,j});
- viz[i][j]++;
- }
- }
- }
- while(q.empty() == false) {
- pair <int, int> node = q.front();
- q.pop();
- if((viz[node.first - 1][node.second] == 0) && (M[node.first - 1][node.second] < h)) {
- viz[node.first - 1][node.second]++;
- q.push({node.first - 1, node.second});
- check(node.first, node.second);
- }
- if((viz[node.first + 1][node.second] == 0) && (M[node.first + 1][node.second] < h)) {
- viz[node.first + 1][node.second]++;
- q.push({node.first + 1, node.second});
- check(node.first, node.second);
- }
- if((viz[node.first ][node.second - 1] == 0) && (M[node.first][node.second - 1] < h)) {
- viz[node.first][node.second - 1]++;
- q.push({node.first, node.second - 1});
- check(node.first, node.second);
- }
- if((viz[node.first][node.second + 1] == 0) && (M[node.first][node.second + 1] < h)) {
- viz[node.first][node.second + 1]++;
- q.push({node.first, node.second + 1});
- check(node.first, node.second);
- }
- }
- for(int i = 1; i <= n; i++) {
- for(int j = 1; j <= m; j++) {
- if(viz[i][j] == 0) {
- rez++;
- }
- }
- }
- out << rez;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement