/// isA AC
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void ACPLS(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
#define tc int tttttt;cin>>tttttt;while(tttttt--)
#define sumrange(l,r,arr) (l==0?arr[r]:arr[r]-arr[l-1])
int dx[8]={0,1,0,-1,1,-1,1,-1};
int dy[8]={1,0,-1,0,1,-1,-1,1};
int n,m;
vector<vector<char>>grid;
vector<vector<bool>>vis;
bool valid(int x, int y, char c){
return x>=1&&x<=n&&y>=1&&y<=m&&grid[x][y]==c;
}
void dfs(int x, int y){
if(vis[x][y])
return;
for(int i = 0; i < 8; i++){
if(valid(x+dx[i],y+dy[i],grid[x][y])){
dfs(x+dx[i],y+dy[i]);
}
}
}
int main(){
ACPLS();
cin>>n>>m;
grid=vector<vector<char>>(n+5,vector<char>(m+5));
vis=vector<vector<bool>>(n+5,vector<bool>(m+5,0));
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
cin>>grid[i][j];
}
}
int ans=0;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
if(!vis[i][j]&&grid[i][j]!='.'){
dfs(i,j);
++ans;
}
}
}
cout<<ans<<'\n';
for(int i = 0; i < 4; i++)
cout<<"0\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
40 ms |
65540 KB |
Execution killed with signal 9 |
2 |
Runtime error |
41 ms |
65540 KB |
Execution killed with signal 9 |
3 |
Runtime error |
42 ms |
65540 KB |
Execution killed with signal 9 |
4 |
Runtime error |
45 ms |
65540 KB |
Execution killed with signal 9 |
5 |
Runtime error |
43 ms |
65540 KB |
Execution killed with signal 9 |
6 |
Runtime error |
42 ms |
65540 KB |
Execution killed with signal 9 |
7 |
Runtime error |
41 ms |
65540 KB |
Execution killed with signal 9 |
8 |
Runtime error |
43 ms |
65540 KB |
Execution killed with signal 9 |
9 |
Runtime error |
41 ms |
65540 KB |
Execution killed with signal 9 |
10 |
Runtime error |
39 ms |
65540 KB |
Execution killed with signal 9 |