#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = array<int, 2>;
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
int main() {
cin.tie(0) -> sync_with_stdio(0);
int n, m;
cin >> n >> m;
vector<string> grid(n);
for (string &i : grid) {
cin >> i;
}
vector vert(n, vector<int>(m, -1));
vector horiz(n, vector<int>(m, -1));
int timer = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j + 2 < m; j++) {
string res = "";
for (int k = 0; k < 3; k++) {
res += grid[i][j + k];
}
if (res != "RGW") continue;
int id = timer++;
for (int k = 0; k < 3; k++) {
horiz[i][j + k] = id;
}
}
}
for (int i = 0; i + 2 < n; i++) {
for (int j = 0; j < m; j++) {
string res = "";
for (int k = 0; k < 3; k++) {
res += grid[i + k][j];
}
if (res != "RGW") continue;
int id = timer++;
for (int k = 0; k < 3; k++) {
vert[i + k][j] = id;
}
}
}
vector<vector<int>> adj(timer);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
int a = vert[i][j], b = horiz[i][j];
if (a != -1 && b != -1) {
timer--;
}
}
}
cout << timer << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |