/**
* author: NotLinux
* created: 09.09.2022 ~ 14:09:50
**/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#ifdef LOCAL
#include "/home/notlinux/debug.h"
#else
#define debug(x...) void(37)
#endif
int n,m;
vector < string > grid;
vector < vector < int > > vis1;
int cnt = 1e12;
int func(int x , int y){
set < int > ret;
vis1.assign(n , vector < int > (m , 0LL));
queue < pair < int , pair < int , int > > > bfs;
bfs.push({0,{x,y}});
while(bfs.size()){
int x = bfs.front().second.first;
int y = bfs.front().second.second;
int w = bfs.front().first;
bfs.pop();
if(x<0 or x>=n or y<0 or y>=m){
ret.insert(cnt);
cnt++;
continue;
}
if(vis1[x][y])continue;
vis1[x][y] = 1;
if(grid[x][y]=='#'){
ret.insert(w);
continue;
}
bfs.push({w+1,{x+1,y}});
bfs.push({w+1,{x-1,y}});
bfs.push({w+1,{x,y+1}});
bfs.push({w+1,{x,y-1}});
}
return ((int)ret.size());
}
void solve(){
cin >> n >> m;
grid.resize(n);
for(auto &inp : grid)cin >> inp;
int ans = 0;
for(int i = 0;i<n;i++)for(int j = 0;j<m;j++){
if(grid[i][j]=='#')continue;
int cnt = func(i,j);
ans += (cnt == 1);
}
cout << ans << endl;
}
int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(nullptr);
int tt=1;
//cin >> tt;
while(tt--)solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1086 ms |
340 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1086 ms |
340 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |