#include<bits/stdc++.h>
#define maxn 500009
using namespace std;
string s[3009];
bool A[3009][3009];
bool B[3009][3009];
int a[3009][3009];
int b[3009][3009];
int k, ans;
int p[6000009], s1[6000009], s2[6000009];
int par(int x){
if(p[x] != x)
p[x] = par(p[x]);
return p[x];
}
void un(int x, int y){
x = par(x);
y = par(y);
if(x == y) return;
if(s1[x] + s2[x] > s1[y] + s2[y]) swap(x,y);
p[x] = y;
ans += max(s1[x]+s1[y], s2[x]+s2[y]) -max(s1[x], s2[x]) -max(s1[y],s2[y]);
}
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, p[k] = k, s1[k] =1, s2[k] =0, ans++;
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, p[k] = k, s1[k] =0, s2[k] =1, ans++;
}
}
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])
{
un(a[i][j], b[i-1][j+1]);
}
if(i >= 2 && B[i-2][j+2]){
un(a[i][j], b[i-2][j+2]);
}
if(B[i][j]){
un(a[i][j], b[i][j]);
}
}
}
}
cout << ans << endl;
}
Compilation message
dango_maker.cpp:24:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
488 KB |
Output is correct |
3 |
Correct |
2 ms |
540 KB |
Output is correct |
4 |
Correct |
2 ms |
596 KB |
Output is correct |
5 |
Correct |
2 ms |
596 KB |
Output is correct |
6 |
Correct |
2 ms |
624 KB |
Output is correct |
7 |
Correct |
2 ms |
624 KB |
Output is correct |
8 |
Correct |
2 ms |
700 KB |
Output is correct |
9 |
Correct |
2 ms |
748 KB |
Output is correct |
10 |
Correct |
2 ms |
748 KB |
Output is correct |
11 |
Correct |
2 ms |
748 KB |
Output is correct |
12 |
Correct |
3 ms |
748 KB |
Output is correct |
13 |
Correct |
2 ms |
748 KB |
Output is correct |
14 |
Correct |
2 ms |
748 KB |
Output is correct |
15 |
Correct |
2 ms |
748 KB |
Output is correct |
16 |
Correct |
2 ms |
748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
488 KB |
Output is correct |
3 |
Correct |
2 ms |
540 KB |
Output is correct |
4 |
Correct |
2 ms |
596 KB |
Output is correct |
5 |
Correct |
2 ms |
596 KB |
Output is correct |
6 |
Correct |
2 ms |
624 KB |
Output is correct |
7 |
Correct |
2 ms |
624 KB |
Output is correct |
8 |
Correct |
2 ms |
700 KB |
Output is correct |
9 |
Correct |
2 ms |
748 KB |
Output is correct |
10 |
Correct |
2 ms |
748 KB |
Output is correct |
11 |
Correct |
2 ms |
748 KB |
Output is correct |
12 |
Correct |
3 ms |
748 KB |
Output is correct |
13 |
Correct |
2 ms |
748 KB |
Output is correct |
14 |
Correct |
2 ms |
748 KB |
Output is correct |
15 |
Correct |
2 ms |
748 KB |
Output is correct |
16 |
Correct |
2 ms |
748 KB |
Output is correct |
17 |
Correct |
2 ms |
748 KB |
Output is correct |
18 |
Correct |
2 ms |
748 KB |
Output is correct |
19 |
Correct |
3 ms |
748 KB |
Output is correct |
20 |
Incorrect |
2 ms |
748 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
488 KB |
Output is correct |
3 |
Correct |
2 ms |
540 KB |
Output is correct |
4 |
Correct |
2 ms |
596 KB |
Output is correct |
5 |
Correct |
2 ms |
596 KB |
Output is correct |
6 |
Correct |
2 ms |
624 KB |
Output is correct |
7 |
Correct |
2 ms |
624 KB |
Output is correct |
8 |
Correct |
2 ms |
700 KB |
Output is correct |
9 |
Correct |
2 ms |
748 KB |
Output is correct |
10 |
Correct |
2 ms |
748 KB |
Output is correct |
11 |
Correct |
2 ms |
748 KB |
Output is correct |
12 |
Correct |
3 ms |
748 KB |
Output is correct |
13 |
Correct |
2 ms |
748 KB |
Output is correct |
14 |
Correct |
2 ms |
748 KB |
Output is correct |
15 |
Correct |
2 ms |
748 KB |
Output is correct |
16 |
Correct |
2 ms |
748 KB |
Output is correct |
17 |
Correct |
2 ms |
748 KB |
Output is correct |
18 |
Correct |
2 ms |
748 KB |
Output is correct |
19 |
Correct |
3 ms |
748 KB |
Output is correct |
20 |
Incorrect |
2 ms |
748 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |