#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define all(x) x.begin(), x.end()
#define x first
#define y second
#define mp make_pair
#define mt make_tuple
const int N = 100;
int n;
int m;
char s[N][N];
bool used[N][N];
bool ok(int i, int j) {
return 0 <= i && i < n && 0 <= j && j < m;
}
int h;
int is;
int js;
void dfs(int i, int j) {
int di = i - is;
int dj = j - js;
h += di * di * di + 100 * dj * dj + dj;
used[i][j] = true;
auto check = [&](int ni, int nj) {
if (ok(ni, nj) && s[ni][nj] == s[i][j] && !used[ni][nj]) {
dfs(ni, nj);
}
};
check(i - 1, j);
check(i + 1, j);
check(i, j - 1);
check(i, j + 1);
}
int cnt[5];
signed main() {
#ifdef LC
assert(freopen("input.txt", "r", stdin));
#endif
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (int i = 0; i < n; ++i) {
cin >> s[i];
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (s[i][j] == '.' || used[i][j]) {
continue;
}
is = i;
js = j;
h = 0;
dfs(i, j);
if (h == 204) {
++cnt[0];
} else if (h == 1406 || h == 36) {
++cnt[1];
} else if (h == 202 || h == 212) {
++cnt[2];
} else if (h == 606 || h == 208) {
++cnt[3];
} else {
++cnt[4];
}
}
}
for (int i = 0; i < 5; ++i) {
cout << cnt[i] << endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |