#include <bits/stdc++.h>
using namespace std;
int n, m, poss[12][12], v[7], i, j;
char a[12][12];
int di[4] = {-1, 1, 0, 0}, dj[4] = {0, 0, -1, 1};
void dfs(int x, int y){
poss[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 && !poss[x + di[t]][y + dj[t]] && a[x][y] == a[x + di[t]][y + dj[t]]) dfs(x + di[t], y+dj[t]);
}
int check(int x, int y){return a[i][j] == a[x + i][y + j];}
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] != '.' && !poss[i][j]){
dfs(i,j);
if (check(0,1) && check(1,0) && check(1,1)) v[1]++;
if ((check(0,1) && check(0,2) && check(0,3)) || (check(1,0) && check(2,0) && check(3,0))) v[2]++;
if ((check(0,1) && check(1,0) && check(1,-1)) || (check(1,0) && check(1,1) && check(2,1))) v[3]++;
if ((check(0,1) && check(1,1) && check(1,2)) || (check(1,0) && check(1,-1) && check(2,-1))) v[4]++;
if ((check(1,-1) && check(1,0) && check(1,1)) || (check(1,-1) && check(1,0) && check(2,0)) ||
(check(0,1) && check(0,2) && check(1,1)) || (check(1,0) && check(1,1) && check(2,0))) v[5]++;
}
for (i = 1;i < 6; i++) cout << v[i] << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
300 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
304 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
300 KB |
Output is correct |