#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ar array
const int dx[4]={0, 1, 0, -1}, dy[4]={1, 0, -1, 0};
int n, m, vis[10][10], ans[5];
string g[10];
vector<ar<int, 2>> c, p[5];
void dfs(int i, int j) {
vis[i][j]=1;
c.push_back({i, j});
for (int k=0; k<4; ++k) {
int a=i+dx[k], b=j+dy[k];
if (0<=a&&a<n&&0<=b&&b<m&&!vis[a][b]&&g[i][j]==g[a][b])
dfs(a, b);
}
}
vector<ar<int, 2>> norm(vector<ar<int, 2>> a) {
vector<ar<int, 2>> b=a;
sort(b.begin(), b.end());
int x=b[0][0], y=b[0][1];
for (ar<int, 2>& a2 : b)
a2[0]-=x, a2[1]-=y;
return b;
}
void rot() {
for (ar<int, 2>& a : c) {
ar<int, 2> b={-a[1], a[0]};
swap(a, b);
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
p[0]={{0, 0}, {0, 1}, {1, 1}, {1, 0}};
p[1]={{0, 0}, {0, 1}, {0, 2}, {0, 3}};
p[2]={{0, 0}, {0, 1}, {1, 0}, {1, -1}};
p[3]={{0, 0}, {0, 1}, {1, 1}, {1, 2}};
p[4]={{0, 0}, {1, 0}, {1, 1}, {1, -1}};
for (int i=0; i<5; ++i)
p[i]=norm(p[i]);
cin >> n >> m;
for (int i=0; i<n; ++i)
cin >> g[i];
for (int i=0; i<n; ++i) {
for (int j=0; j<m; ++j) {
if (vis[i][j]||g[i][j]=='.')
continue;
dfs(i, j);
assert(c.size()==4);
for (int k=0; k<5; ++k) {
for (int k2=0; k2<4; ++k2) {
if (norm(c)==p[k]) {
++ans[k];
break;
}
rot();
}
}
c.clear();
}
}
for (int i=0; i<5; ++i)
cout << ans[i] << " ";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |