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>
//#define int long long
#define all(x) x.begin(), x.end()
using namespace std;
const int MAXN = 3050;
const int MAXC = MAXN * MAXN;
vector<int> sup[MAXN][MAXN];
vector<int> g[MAXC];
int used[MAXN];
int cc[2];
void dfs(int v, int col) {
cc[col]++;
used[v] = 1;
for (int u : g[v]) {
if (!used[u]) {
dfs(u, 1 - col);
}
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, m;
cin >> n >> m;
vector<string> a(n);
for (auto &el : a) {
cin >> el;
}
int cnt_ = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j + 2 < m; j++) {
if (a[i][j] == 'R' && a[i][j + 1] == 'G' && a[i][j + 2] == 'W') {
for (int j2 = j; j2 < j + 3; j2++) {
sup[i][j2].push_back(cnt_);
}
cnt_++;
}
}
}
for (int i = 0; i + 2 < n; i++) {
for (int j = 0; j < m; j++) {
if (a[i][j] == 'R' && a[i + 1][j] == 'G' && a[i + 2][j] == 'W') {
for (int i2 = i; i2 < i + 3; i2++) {
sup[i2][j].push_back(cnt_);
}
cnt_++;
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if ((int) sup[i][j].size() == 2) {
int v = sup[i][j][0], u = sup[i][j][1];
g[v].push_back(u);
g[u].push_back(v);
}
}
}
int res = 0;
for (int v = 0; v < cnt_; v++) {
if (!used[v]) {
cc[0] = cc[1] = 0;
dfs(v, 0);
res += max(cc[0], cc[1]);
}
}
cout << res << '\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... |