#include<bits/stdc++.h>
using namespace std;
char a[12][12];
int used[12][12];
int ans[5];
vector < pair < int, int > > go = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
vector < pair < int, int > > Q;
map < vector < pair < int, int > >, int > t = {
{{{0, 0}, {0, 1}, {1, 0}, {1, 1}}, 0},
{{{0, 0}, {0, 1}, {0, 2}, {0, 3}}, 1},
{{{0, 0}, {1, 0}, {2, 0}, {3, 0}}, 1},
{{{0, 0}, {1, 0}, {0, 1}, {1, -1}}, 2},
{{{0, 0}, {0, 1}, {1, 1}, {1, 2}}, 3},
{{{0, 0}, {1, 0}, {1, 1}, {2, 1}}, 2},
{{{0, 0}, {1, 0}, {1, -1}, {2, -1}}, 3}
};
void dfs(int i, int j) {
Q.push_back({i, j});
used[i][j] = 1;
for (auto u : go) {
i += u.first, j += u.second;
if (used[i][j] == 0 && a[i][j] == a[i - u.first][j - u.second]) {
dfs(i, j);
}
i -= u.first, j -= u.second;
}
}
main() {
#ifdef HOME
//freopen("input.txt", "r", stdin);
#endif // HOME
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
for (int i = 0; i <= 11; ++i) {
for (int j = 0; j <= 11; ++j) a[i][j] = '.';
}
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] != '.' && used[i][j] == 0) {
Q = {};
dfs(i, j);
assert((int)Q.size() == 4);
int oksik = 4;
for (int pos = 3; pos >= 0; --pos) Q[pos].first -= Q[0].first, Q[pos].second -= Q[0].second;
for (int pos = 0; pos < 24; ++pos) {
if (t.find(Q) != t.end()) oksik = t[Q];
if (pos != 23) next_permutation(Q.begin(), Q.end());
}
ans[oksik]++;
}
}
}
for (int i = 0; i <= 4; ++i) cout << ans[i] << '\n';
return 0;
}
Compilation message
tetris.cpp:33:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main() {
^
# |
Verdict |
Execution time |
Memory |
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 |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |