#include <iostream>
using namespace std;
int n,m,i,j,ok[12][12],v[7];
char a[12][12];
int di[4]={1,-1,0,0};
int dj[4]={0,0,1,-1};
void fill(int x,int y){
ok[x][y]=1;
for (int t=0;t<4;t++)
if (x+di[t]>0 && x+di[t]<=n && y+dj[t]>0 && y+dj[t]<=m && !ok[x+di[t]][y+dj[t]] && a[x][y]==a[x+di[t]][y+dj[t]])
fill(x+di[t],y+dj[t]);
}
int te(int x,int y){
return a[i][j]==a[i+x][j+y];
}
int main(){
cin>>n>>m;
for (i=1;i<=n;i++)
for (j=1;j<=m;j++)
cin>>a[i][j];
for (i=1;i<=n;i++)
for (j=1;j<=m;j++)
if (a[i][j]!='.' && !ok[i][j]){
fill(i,j);
if (te(0,1) && te(1,0) && te(1,1))
v[1]++;
if ((te(0,1) && te(0,2) && te(0,3)) || (te(1,0) && te(2,0) && te(3,0)))
v[2]++;
if ((te(0,1) && te(1,0) && te(1,-1)) || (te(1,0) && te(1,1) && te(2,1)))
v[3]++;
if ((te(0,1) && te(1,1) && te(1,2)) || (te(1,0) && te(1,-1) && te(2,-1)))
v[4]++;
if ((te(1,-1) && te(1,0) && te(1,1)) || (te(1,-1) && te(1,0) && te(2,0)) ||
(te(0,1) && te(0,2) && te(1,1)) || (te(1,0) && te(1,1) && te(2,0)))
v[5]++;
}
for (i=1;i<6;i++)
cout<<v[i]<<'\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |