#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pi;
typedef long long int lint;
const int inf = 0x3f3f3f3f;
const int maxn = 15;
int n, m;
char a[maxn][maxn];
bool memo[maxn][maxn];
int cnt[5];
bool fuki1(int x, int y, char c) {
if(c == a[x + 1][y] and c == a[x][y + 1] and c == a[x + 1][y + 1]) {
memo[x][y] = memo[x + 1][y] = memo[x][y + 1] = memo[x + 1][y + 1] = 1;
return 1;
}
return 0;
}
bool fuki2(int x, int y, char c) {
if(a[x + 1][y] == c and a[x + 2][y] == c and a[x + 3][y] == c) {
memo[x][y] = memo[x + 1][y] = memo[x + 2][y] = memo[x + 3][y] = 1;
return 1;
}
if(c == a[x][y + 1] and c == a[x][y + 2] and c == a[x][y + 3]) {
memo[x][y] = memo[x][y + 1] = memo[x][y + 2] = memo[x][y + 3] = 1;
return 1;
}
return 0;
}
bool fuki3(int x, int y, char c) {
if(c == a[x + 1][y] and c == a[x][y + 1] and c == a[x + 1][y - 1]) {
memo[x][y] = memo[x][y + 1] = memo[x + 1][y] = memo[x + 1][y - 1] = 1;
return 1;
}
if(c == a[x + 1][y] and c == a[x + 1][y + 1] and c == a[x + 2][y + 1]) {
memo[x][y] = memo[x + 1][y] = memo[x + 1][y + 1] = memo[x + 2][y + 1] = 1;
return 1;
}
return 0;
}
bool fuki4(int x, int y, char c) {
if(c == a[x][y + 1] and c == a[x + 1][y + 1] and c == a[x + 1][y + 2]) {
memo[x][y] = memo[x][y + 1] = memo[x + 1][y + 1] = memo[x + 1][y + 2] = 1;
return 1;
}
if(c == a[x + 1][y] and c == a[x + 1][y - 1] and c == a[x + 2][y - 1]) {
memo[x][y] = memo[x + 1][y] = memo[x + 1][y - 1] = memo[x + 2][y - 1] = 1;
return 1;
}
return 0;
}
bool fuki5(int x, int y, char c) {
if(c == a[x + 1][y] and c == a[x + 1][y - 1] and c == a[x + 1][y + 1]) {
memo[x][y] = memo[x + 1][y + 1] = memo[x + 1][y - 2] = memo[x + 1][y] = 1;
return 1;
}
if(c == a[x + 1][y] and c == a[x + 1][y - 1] and c == a[x + 2][y]) {
memo[x][y] = memo[x + 1][y] = memo[x + 1][y - 1] = memo[x + 2][y] = 1;
return 1;
}
if(c == a[x + 1][y] and c == a[x + 2][y] and c == a[x + 1][y + 1]) {
memo[x][y] = memo[x + 1][y] = memo[x + 2][y] = memo[x + 1][y + 1] = 1;
return 1;
}
if(c == a[x][y + 1] and c == a[x][y + 2] and c == a[x + 1][y + 1]) {
memo[x][y] = memo[x][y + 1] = memo[x][y + 2] = memo[x + 1][y + 1] = 1;
return 1;
}
return 0;
}
int main ()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= m; ++j)
cin >> a[i][j];
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= m; ++j) {
if(a[i][j] != '.' and not memo[i][j]) {
// cout << i << " " << j << endl;
if(fuki1(i, j, a[i][j])) {
// cout << 1 << endl;
cnt[0]++;
} else if(fuki2(i, j, a[i][j])) {
// cout << 2 << endl;
cnt[1]++;
} else if(fuki3(i, j, a[i][j])) {
// cout << 3 << endl;
cnt[2]++;
} else if(fuki4(i, j, a[i][j])) {
// cout << 4 << endl;
cnt[3]++;
} else if(fuki5(i, j, a[i][j])) {
// cout << 5 << endl;
cnt[4]++;
}
}
}
}
for(int i = 0; i < 5; ++i) {
if(i) cout << endl;
cout << cnt[i];
}
return 0;
}
//pcelica maja
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
512 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |