#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]);
s1[y] += s1[x];
s2[y] += s2[x];
}
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:26:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
660 KB |
Output is correct |
3 |
Correct |
2 ms |
660 KB |
Output is correct |
4 |
Correct |
2 ms |
692 KB |
Output is correct |
5 |
Correct |
2 ms |
692 KB |
Output is correct |
6 |
Correct |
2 ms |
736 KB |
Output is correct |
7 |
Correct |
2 ms |
736 KB |
Output is correct |
8 |
Correct |
2 ms |
736 KB |
Output is correct |
9 |
Correct |
3 ms |
736 KB |
Output is correct |
10 |
Correct |
3 ms |
736 KB |
Output is correct |
11 |
Correct |
2 ms |
736 KB |
Output is correct |
12 |
Correct |
3 ms |
736 KB |
Output is correct |
13 |
Correct |
2 ms |
736 KB |
Output is correct |
14 |
Correct |
2 ms |
736 KB |
Output is correct |
15 |
Correct |
2 ms |
736 KB |
Output is correct |
16 |
Correct |
3 ms |
736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
660 KB |
Output is correct |
3 |
Correct |
2 ms |
660 KB |
Output is correct |
4 |
Correct |
2 ms |
692 KB |
Output is correct |
5 |
Correct |
2 ms |
692 KB |
Output is correct |
6 |
Correct |
2 ms |
736 KB |
Output is correct |
7 |
Correct |
2 ms |
736 KB |
Output is correct |
8 |
Correct |
2 ms |
736 KB |
Output is correct |
9 |
Correct |
3 ms |
736 KB |
Output is correct |
10 |
Correct |
3 ms |
736 KB |
Output is correct |
11 |
Correct |
2 ms |
736 KB |
Output is correct |
12 |
Correct |
3 ms |
736 KB |
Output is correct |
13 |
Correct |
2 ms |
736 KB |
Output is correct |
14 |
Correct |
2 ms |
736 KB |
Output is correct |
15 |
Correct |
2 ms |
736 KB |
Output is correct |
16 |
Correct |
3 ms |
736 KB |
Output is correct |
17 |
Correct |
3 ms |
736 KB |
Output is correct |
18 |
Correct |
3 ms |
832 KB |
Output is correct |
19 |
Correct |
3 ms |
832 KB |
Output is correct |
20 |
Correct |
3 ms |
832 KB |
Output is correct |
21 |
Correct |
3 ms |
832 KB |
Output is correct |
22 |
Correct |
3 ms |
832 KB |
Output is correct |
23 |
Correct |
2 ms |
832 KB |
Output is correct |
24 |
Correct |
2 ms |
832 KB |
Output is correct |
25 |
Correct |
2 ms |
832 KB |
Output is correct |
26 |
Correct |
2 ms |
832 KB |
Output is correct |
27 |
Correct |
2 ms |
832 KB |
Output is correct |
28 |
Correct |
3 ms |
832 KB |
Output is correct |
29 |
Correct |
3 ms |
832 KB |
Output is correct |
30 |
Correct |
2 ms |
832 KB |
Output is correct |
31 |
Correct |
2 ms |
860 KB |
Output is correct |
32 |
Correct |
3 ms |
860 KB |
Output is correct |
33 |
Correct |
2 ms |
876 KB |
Output is correct |
34 |
Incorrect |
2 ms |
876 KB |
Output isn't correct |
35 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
660 KB |
Output is correct |
3 |
Correct |
2 ms |
660 KB |
Output is correct |
4 |
Correct |
2 ms |
692 KB |
Output is correct |
5 |
Correct |
2 ms |
692 KB |
Output is correct |
6 |
Correct |
2 ms |
736 KB |
Output is correct |
7 |
Correct |
2 ms |
736 KB |
Output is correct |
8 |
Correct |
2 ms |
736 KB |
Output is correct |
9 |
Correct |
3 ms |
736 KB |
Output is correct |
10 |
Correct |
3 ms |
736 KB |
Output is correct |
11 |
Correct |
2 ms |
736 KB |
Output is correct |
12 |
Correct |
3 ms |
736 KB |
Output is correct |
13 |
Correct |
2 ms |
736 KB |
Output is correct |
14 |
Correct |
2 ms |
736 KB |
Output is correct |
15 |
Correct |
2 ms |
736 KB |
Output is correct |
16 |
Correct |
3 ms |
736 KB |
Output is correct |
17 |
Correct |
3 ms |
736 KB |
Output is correct |
18 |
Correct |
3 ms |
832 KB |
Output is correct |
19 |
Correct |
3 ms |
832 KB |
Output is correct |
20 |
Correct |
3 ms |
832 KB |
Output is correct |
21 |
Correct |
3 ms |
832 KB |
Output is correct |
22 |
Correct |
3 ms |
832 KB |
Output is correct |
23 |
Correct |
2 ms |
832 KB |
Output is correct |
24 |
Correct |
2 ms |
832 KB |
Output is correct |
25 |
Correct |
2 ms |
832 KB |
Output is correct |
26 |
Correct |
2 ms |
832 KB |
Output is correct |
27 |
Correct |
2 ms |
832 KB |
Output is correct |
28 |
Correct |
3 ms |
832 KB |
Output is correct |
29 |
Correct |
3 ms |
832 KB |
Output is correct |
30 |
Correct |
2 ms |
832 KB |
Output is correct |
31 |
Correct |
2 ms |
860 KB |
Output is correct |
32 |
Correct |
3 ms |
860 KB |
Output is correct |
33 |
Correct |
2 ms |
876 KB |
Output is correct |
34 |
Incorrect |
2 ms |
876 KB |
Output isn't correct |
35 |
Halted |
0 ms |
0 KB |
- |