#include <bits/stdc++.h>
using namespace std;
typedef tuple<int,int,int> iii;
int n,m;
string s[3005];
vector <int> G[10000005];
bool visited[10000005];
bool mark[2][3005][3005]; // 0 = down, 1 = right
int glob, cnt;
void dfs(int u, int color){
visited[u] = 1;
glob ++;
cnt += (color == 0);
for(auto v: G[u]){
//cout << u << ' ' << v << endl;
if (!visited[v])
dfs(v, color ^= 1);
}
}
int main(){
iostream::sync_with_stdio(0);
cin >> n >> m;
for(int i=1;i<=n;i++) cin >> s[i], s[i] = '0' + s[i];
int ans = 0;
vector <iii> lst;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if (i <= n-2 && s[i][j] == 'R' && s[i+1][j] == 'G' && s[i+2][j] == 'W')
mark[0][i][j] = 1,
lst.push_back(iii(0,i,j));
if (j <= m-2 && s[i][j] == 'R' && s[i][j+1] == 'G' && s[i][j+2] == 'W')
mark[1][i][j] = 1,
lst.push_back(iii(1,i,j));
}
}
sort(lst.begin(), lst.end());
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if (mark[0][i][j]){
int id1 = lower_bound(lst.begin(), lst.end(), iii(0,i,j)) - lst.begin() + 1;
int id2;
if (mark[1][i][j]){
id2 = lower_bound(lst.begin(), lst.end(), iii(1,i,j)) - lst.begin() + 1;
G[id1].push_back(id2);
}
if (i < n && j > 1 && mark[1][i+1][j-1]){
id2 = lower_bound(lst.begin(), lst.end(), iii(1,i+1,j-1)) - lst.begin() + 1;
G[id1].push_back(id2);
}
}
if (mark[1][i][j]){
int id1 = lower_bound(lst.begin(), lst.end(), iii(1,i,j)) - lst.begin() + 1;
int id2;
if (mark[0][i][j]){
id2 = lower_bound(lst.begin(), lst.end(), iii(0,i,j)) - lst.begin() + 1;
G[id1].push_back(id2);
}
if (i > 1 && j < m && mark[0][i-1][j+1]){
id2 = lower_bound(lst.begin(), lst.end(), iii(0,i-1,j+1)) - lst.begin() + 1;
G[id1].push_back(id2);
}
}
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if (mark[0][i][j]){
int id = lower_bound(lst.begin(), lst.end(), iii(0,i,j)) - lst.begin() + 1;
if (visited[id]) continue;
glob = cnt = 0;
dfs(id, 0);
ans += max(cnt, glob-cnt);
}
if (mark[1][i][j]){
int id = lower_bound(lst.begin(), lst.end(), iii(1,i,j)) - lst.begin() + 1;
if (visited[id]) continue;
glob = cnt = 0;
dfs(id, 0);
ans += max(cnt, glob-cnt);
}
}
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
128 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
128 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
128 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |