This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
using namespace std;
#ifdef Nero
#include "Deb.h"
#else
#define deb(...)
#endif
const int N = 3003;
char c[N][N];
int used[N][N];
set<int> g[N];
int intersect[N * N];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
cin >> c[i][j];
}
}
int tmp = 0, num = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m - 2; ++j) {
if (c[i][j] == 'R' && c[i][j + 1] == 'G' && c[i][j + 2] == 'W') {
tmp++; num++;
used[i][j] = used[i][j + 1] = used[i][j + 2] = num;
}
}
}
int original = num;
for (int i = 0; i < n - 2; ++i) {
for (int j = 0; j < m; ++j) {
if (c[i][j] == 'R' && c[i + 1][j] == 'G' && c[i + 2][j] == 'W') {
num++;
for (int k = 0; k < 3; ++k) {
if (used[i + k][j]) {
intersect[num]++;
}
}
for (int k = 0; k < 3; ++k) {
if (used[i + k][j]) {
g[num].insert(used[i + k][j]);
g[used[i + k][j]].insert(num);
}
}
if (intersect[num] == 0) {
tmp++;
}
}
}
}
int ans = tmp;
queue<int> que;
for (int i = 1; i <= original; ++i) {
for (int u : g[i]) {
if (intersect[u] == 1) {
que.push(i);
break;
}
}
}
while (!que.empty()) {
int v = que.front();
que.pop();
tmp--;
for (int u : g[v]) {
--intersect[u];
g[u].erase(v);
if (intersect[u] == 0) {
tmp++;
} else if (intersect[u] == 1) {
que.push(*g[u].begin());
}
}
}
cout << ans << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |