#include <bits/stdc++.h>
#define ii pair <int, int>
#define fi first.first
#define se first.second
#define th second
using namespace std;
const int O = 3e3 + 5;
const int base = 500;
const int mod = 998244353;
int n, m, cnt, cal, c[O][O], dd[2][O][O];
char a[O][O];
vector <pair <ii, int>> g[2][O][O];
void dfs(pair <ii, int> u){
queue <pair <ii, int>> q;
q.push(u);
while (q.size()){
u = q.front(); q.pop();
cnt += u.fi == 0; cal += 1;
dd[u.fi][u.se][u.th] = 1;
for (auto v : g[u.fi][u.se][u.th]){
if (!dd[v.fi][v.se][v.th]) q.push(v);
}
}
}
main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; ++ i){
for (int j = 1; j <= m; ++ j){
cin >> a[i][j];
if (a[i][j] == 'W' && j >= 3){
c[i][j - 2] += (a[i][j - 2] == 'R' && a[i][j - 1] == 'G');
}
if (a[i][j] == 'W' && i >= 3){
c[i - 2][j] += 2 * (a[i - 2][j] == 'R' && a[i - 1][j] == 'G');
}
}
}
for (int i = 1; i <= n; ++ i){
for (int j = 1; j <= m - 2; ++ j){
if (c[i][j] & 1){
if (i > 2 && (c[i - 2][j + 2] & 2)){
g[0][i][j].push_back(make_pair(make_pair(1, i - 2), j + 2));
g[1][i - 2][j + 2].push_back(make_pair(make_pair(0, i), j));
}
if (i > 1 && (c[i - 1][j + 1] & 2)){
g[0][i][j].push_back(make_pair(make_pair(1, i - 1), j + 1));
g[1][i - 1][j + 1].push_back(make_pair(make_pair(0, i), j));
}
if (c[i][j] & 2){
g[0][i][j].push_back(make_pair(make_pair(1, i), j));
g[1][i][j].push_back(make_pair(make_pair(0, i), j));
}
}
}
}
int res = 0;
for (int i = 1; i <= n; ++ i){
for (int j = 1; j <= m; ++ j){
if (c[i][j] > 0){
cnt = cal = 0;
if (c[i][j] & 1 && !dd[0][i][j]){
dfs(make_pair(make_pair(0, i), j));
}
else if (!dd[1][i][j]){
dfs(make_pair(make_pair(1, i), j));
}
res += max(cnt, cal - cnt);
}
}
}
cout << res;
}
Compilation message
dango_maker.cpp:32:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
32 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
61 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
61 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
61 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |