#include<bits/stdc++.h>
#define maxn 500009
using namespace std;
string s[3009];
int A[3009][3009];
int B[3009][3009];
int a[3009][3009];
int b[3009][3009];
int k, Bl, Wi;
vector<int> v[6000009];
int f[6000009];
void dfs(int x, int c){
f[x] = 1;
if(c == 1) Wi++;
else Bl++;
for(int i = 0; i < v[x].size(); i++)
if(!f[v[x][i]])dfs(v[x][i], 1 - c);
}
main(){
int n, m;
cin >> n >> m;
for(int i = 0; i < n; i++){
cin >> s[i];
}
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if(j + 2 < m && s[i][j] == 'R'
&& s[i][j+1] == 'G'
&& s[i][j+2] == 'W')
A[i][j] = 1, a[i][j] = ++k;
if(i + 2 < n && s[i][j] == 'R'
&& s[i+1][j] == 'G'
&& s[i+2][j] == 'W')
B[i][j] = 1, b[i][j] = ++k;
}
}
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if(A[i][j])
{ if (i >= 1 && B[i-1][j+1])
{
v[a[i][j]].push_back(b[i-1][j+1]);
v[b[i-1][j+1]].push_back(a[i][j]);
}
if(i >= 2 && B[i-2][j+2]){
v[a[i][j]].push_back(b[i-2][j+2]);
v[b[i-2][j+2]].push_back(a[i][j]);
}
if(B[i][j]){
v[a[i][j]].push_back(b[i][j]);
v[b[i][j]].push_back(a[i][j]);
}
}
}
}
int ans = 0;
for(int i = 1; i <= k; i++){
if(f[i] == 0){
Bl = 0;
Wi = 0;
dfs(i, 0);
ans += max(Bl,Wi);
}
}
cout << ans << endl;
}
Compilation message
dango_maker.cpp: In function 'void dfs(int, int)':
dango_maker.cpp:16:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < v[x].size(); i++)
~~^~~~~~~~~~~~~
dango_maker.cpp: At global scope:
dango_maker.cpp:19:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
134 ms |
141360 KB |
Output is correct |
2 |
Correct |
127 ms |
141360 KB |
Output is correct |
3 |
Correct |
127 ms |
141428 KB |
Output is correct |
4 |
Correct |
139 ms |
141524 KB |
Output is correct |
5 |
Correct |
148 ms |
141524 KB |
Output is correct |
6 |
Correct |
140 ms |
141556 KB |
Output is correct |
7 |
Correct |
130 ms |
141644 KB |
Output is correct |
8 |
Correct |
135 ms |
141732 KB |
Output is correct |
9 |
Correct |
134 ms |
141732 KB |
Output is correct |
10 |
Correct |
127 ms |
141732 KB |
Output is correct |
11 |
Correct |
143 ms |
141732 KB |
Output is correct |
12 |
Correct |
129 ms |
141732 KB |
Output is correct |
13 |
Correct |
139 ms |
141732 KB |
Output is correct |
14 |
Correct |
137 ms |
141732 KB |
Output is correct |
15 |
Correct |
135 ms |
141732 KB |
Output is correct |
16 |
Correct |
133 ms |
141732 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
134 ms |
141360 KB |
Output is correct |
2 |
Correct |
127 ms |
141360 KB |
Output is correct |
3 |
Correct |
127 ms |
141428 KB |
Output is correct |
4 |
Correct |
139 ms |
141524 KB |
Output is correct |
5 |
Correct |
148 ms |
141524 KB |
Output is correct |
6 |
Correct |
140 ms |
141556 KB |
Output is correct |
7 |
Correct |
130 ms |
141644 KB |
Output is correct |
8 |
Correct |
135 ms |
141732 KB |
Output is correct |
9 |
Correct |
134 ms |
141732 KB |
Output is correct |
10 |
Correct |
127 ms |
141732 KB |
Output is correct |
11 |
Correct |
143 ms |
141732 KB |
Output is correct |
12 |
Correct |
129 ms |
141732 KB |
Output is correct |
13 |
Correct |
139 ms |
141732 KB |
Output is correct |
14 |
Correct |
137 ms |
141732 KB |
Output is correct |
15 |
Correct |
135 ms |
141732 KB |
Output is correct |
16 |
Correct |
133 ms |
141732 KB |
Output is correct |
17 |
Correct |
125 ms |
141732 KB |
Output is correct |
18 |
Correct |
131 ms |
141732 KB |
Output is correct |
19 |
Correct |
136 ms |
141772 KB |
Output is correct |
20 |
Correct |
136 ms |
141772 KB |
Output is correct |
21 |
Correct |
147 ms |
141812 KB |
Output is correct |
22 |
Correct |
127 ms |
141852 KB |
Output is correct |
23 |
Correct |
130 ms |
141852 KB |
Output is correct |
24 |
Correct |
132 ms |
141852 KB |
Output is correct |
25 |
Correct |
145 ms |
141852 KB |
Output is correct |
26 |
Correct |
136 ms |
141852 KB |
Output is correct |
27 |
Correct |
134 ms |
141888 KB |
Output is correct |
28 |
Correct |
136 ms |
141916 KB |
Output is correct |
29 |
Correct |
145 ms |
141948 KB |
Output is correct |
30 |
Correct |
136 ms |
141948 KB |
Output is correct |
31 |
Correct |
147 ms |
141948 KB |
Output is correct |
32 |
Correct |
155 ms |
141948 KB |
Output is correct |
33 |
Correct |
139 ms |
141956 KB |
Output is correct |
34 |
Incorrect |
132 ms |
141960 KB |
Output isn't correct |
35 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
134 ms |
141360 KB |
Output is correct |
2 |
Correct |
127 ms |
141360 KB |
Output is correct |
3 |
Correct |
127 ms |
141428 KB |
Output is correct |
4 |
Correct |
139 ms |
141524 KB |
Output is correct |
5 |
Correct |
148 ms |
141524 KB |
Output is correct |
6 |
Correct |
140 ms |
141556 KB |
Output is correct |
7 |
Correct |
130 ms |
141644 KB |
Output is correct |
8 |
Correct |
135 ms |
141732 KB |
Output is correct |
9 |
Correct |
134 ms |
141732 KB |
Output is correct |
10 |
Correct |
127 ms |
141732 KB |
Output is correct |
11 |
Correct |
143 ms |
141732 KB |
Output is correct |
12 |
Correct |
129 ms |
141732 KB |
Output is correct |
13 |
Correct |
139 ms |
141732 KB |
Output is correct |
14 |
Correct |
137 ms |
141732 KB |
Output is correct |
15 |
Correct |
135 ms |
141732 KB |
Output is correct |
16 |
Correct |
133 ms |
141732 KB |
Output is correct |
17 |
Correct |
125 ms |
141732 KB |
Output is correct |
18 |
Correct |
131 ms |
141732 KB |
Output is correct |
19 |
Correct |
136 ms |
141772 KB |
Output is correct |
20 |
Correct |
136 ms |
141772 KB |
Output is correct |
21 |
Correct |
147 ms |
141812 KB |
Output is correct |
22 |
Correct |
127 ms |
141852 KB |
Output is correct |
23 |
Correct |
130 ms |
141852 KB |
Output is correct |
24 |
Correct |
132 ms |
141852 KB |
Output is correct |
25 |
Correct |
145 ms |
141852 KB |
Output is correct |
26 |
Correct |
136 ms |
141852 KB |
Output is correct |
27 |
Correct |
134 ms |
141888 KB |
Output is correct |
28 |
Correct |
136 ms |
141916 KB |
Output is correct |
29 |
Correct |
145 ms |
141948 KB |
Output is correct |
30 |
Correct |
136 ms |
141948 KB |
Output is correct |
31 |
Correct |
147 ms |
141948 KB |
Output is correct |
32 |
Correct |
155 ms |
141948 KB |
Output is correct |
33 |
Correct |
139 ms |
141956 KB |
Output is correct |
34 |
Incorrect |
132 ms |
141960 KB |
Output isn't correct |
35 |
Halted |
0 ms |
0 KB |
- |