#include <bits/stdc++.h>
using namespace std;
#ifdef Ramzi
#include "debug.h"
#else
#define debug(...)
#endif
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
vector<string> s(n);
for (int i = 0; i < n; i++) {
cin >> s[i];
}
auto safe = [&](int i, int j) -> bool {
return (i >= 0 && i < n && j >= 0 && j < m);
};
vector use(n, vector<int>(m));
auto f1 = [&](int x, int y) -> int {
vector<int> dx = {0, 1, 1};
vector<int> dy = {1, 1, 0};
vector<pair<int, int>> p;
p.push_back({x, y});
for (int i = 0; i < 3; i++) {
int nx = x + dx[i];
int ny = y + dy[i];
if (!safe(nx, ny) || s[nx][ny] != s[x][y]) {
return 0;
}
p.push_back({nx, ny});
}
for (auto [a, b]: p) {
use[a][b] = 1;
}
return 1;
};
auto f2 = [&](int x, int y) -> int {
bool ret = true, ret2 = true;
vector<pair<int, int>> p, p2;
p.push_back({x, y});
p2.push_back({x, y});
for (int i = 1; i < 4; i++) {
if (!safe(x, y + i) || s[x][y + i] != s[x][y]) {
ret = false;
}
p.push_back({x, y + i});
if (!safe(x + i, y) || s[x + i][y] != s[x][y]) {
ret2 = false;
}
p2.push_back({x + i, y});
}
if (ret) {
for (auto [a, b]: p) {
use[a][b] = 1;
}
} else if (ret2){
for (auto [a, b]: p2) {
use[a][b] = 1;
}
}
return (ret || ret2 ? 1 : 0);
};
auto f3 = [&](int x, int y) -> bool {
vector<int> dx = {0, 1, 1};
vector<int> dy = {1, 0, -1};
vector<pair<int, int>> p, p2;
p.push_back({x, y});
p2.push_back({x, y});
bool ret = true;
for (int i = 0; i < 3; i++) {
int nx = x + dx[i];
int ny = y + dy[i];
if (!safe(nx, ny) || s[nx][ny] != s[x][y]) {
ret = false;
}
p.push_back({nx, ny});
}
dx = {1, 1, 2};
dy = {0, 1, 1};
bool ret2 = true;
for (int i = 0; i < 3; i++) {
int nx = x + dx[i];
int ny = y + dy[i];
if (!safe(nx, ny) || s[nx][ny] != s[x][y]) {
ret2 = false;
}
p2.push_back({nx, ny});
}
if (ret) {
for (auto [a, b]: p) {
use[a][b] = 1;
}
} else if (ret2){
for (auto [a, b]: p2) {
use[a][b] = 1;
}
}
return (ret || ret2 ? 1 : 0);
};
auto f4 = [&](int x, int y) {
vector<pair<int, int>> p, p2;
p.push_back({x, y});
p2.push_back({x, y});
vector<int> dx = {0, 1, 1};
vector<int> dy = {1, 1, 2};
bool ret = true;
for (int i = 0; i < 3; i++) {
int nx = x + dx[i];
int ny = y + dy[i];
if (!safe(nx, ny) || s[nx][ny] != s[x][y]) {
ret = false;
}
p.push_back({nx, ny});
}
dx = {1, 1, 2};
dy = {0, -1, -1};
bool ret2 = true;
for (int i = 0; i < 3; i++) {
int nx = x + dx[i];
int ny = y + dy[i];
if (!safe(nx, ny) || s[nx][ny] != s[x][y]) {
ret2 = false;
}
p2.push_back({nx, ny});
}
if (ret) {
for (auto [a, b]: p) {
use[a][b] = 1;
}
} else if (ret2) {
for (auto [a, b]: p2) {
use[a][b] = 1;
}
}
return (ret || ret2 ? 1 : 0);
};
auto f5 = [&](int x, int y) -> int {
vector<int> dx = {1, 1, 1};
vector<int> dy = {-1, 0, 1};
bool ret = true;
vector<pair<int, int>> p, p2;
p.push_back({x, y});
p2.push_back({x, y});
for (int i = 0; i < 3; i++) {
int nx = x + dx[i];
int ny = y + dy[i];
if (!safe(nx, ny) || s[nx][ny] != s[x][y]) {
ret = false;
}
p.push_back({nx, ny});
}
dx = {0, 0, 1};
dy = {1, 2, 1};
bool ret2 = true;
for (int i = 0; i < 3; i++) {
int nx = x + dx[i];
int ny = y + dy[i];
if (!safe(nx, ny) || s[nx][ny] != s[x][y]) {
ret2 = false;
}
p2.push_back({nx, ny});
}
if (ret) {
for (auto [a, b]: p) {
use[a][b] = 1;
}
} else if (ret2) {
for (auto [a, b]: p2) {
use[a][b] = 1;
}
}
return (ret || ret2 ? 1 : 0);
};
vector<int> cnt(5);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (!use[i][j] && s[i][j] != '.') {
cnt[0] += f1(i, j);
cnt[1] += f2(i, j);
cnt[2] += f3(i, j);
cnt[3] += f4(i, j);
cnt[4] += f5(i, j);
}
}
}
for (int i = 0; i < 5; i++) {
cout << cnt[i] << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
604 KB |
Output isn't correct |
10 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |