#include<bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<lld,lld> pii;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define trav(a,v) for(auto a:v)
int has[3000][3000][2];
int n,m;
bool valid(int x, int y){
if(x>=0 && x<n && y>=0 && y<m)return true;
return false;
}
bool visited[10000000];
int size;
int independent;
vector<int> graph[1000000];
void DFS(int node, int parity){
independent+=parity;
visited[node]=true;
size++;
trav(v,graph[node]){
if(!visited[v])DFS(v,(parity+1)%2);
}
}
int main(){
cin>>n>>m;
string table[n];
rep(i,0,n){
cin>>table[i];
}
int V=0;
int H=0;
vector<pii> v;
vector<pii> h;
rep(i,0,n){
rep(j,0,m){
has[i][j][0]=-1;
has[i][j][1]=-1;
if(table[i][j]=='R'){
if(i+2<n && table[i+1][j]=='G' && table[i+2][j]=='W'){
has[i][j][0]=V;
V++;
v.push_back(pii(i,j));
}
if(j+2<m && table[i][j+1]=='G' && table[i][j+2]=='W'){
has[i][j][1]=H;
H++;
h.push_back(pii(i,j));
}
}
}
}
rep(i,0,n){
rep(j,0,m){
if(has[i][j][0]!=-1){
if(has[i][j][1]!=-1){
graph[has[i][j][0]].push_back(has[i][j][1]+V);
graph[has[i][j][1]+V].push_back(has[i][j][0]);
}
if(valid(i+1,j-1) && has[i+1][j-1][1]!=-1){
graph[has[i][j][0]].push_back(has[i+1][j-1][1]+V);
graph[has[i+1][j-1][1]+V].push_back(has[i][j][0]);
}
if(valid(i+2,j-2) && has[i+2][j-2][1]!=-1){
graph[has[i][j][0]].push_back(has[i+2][j-2][1]+V);
graph[has[i+2][j-2][1]+V].push_back(has[i][j][0]);
}
}
}
}
/*cout<<V+H<<endl;
rep(i,0,V+H){
trav(v,graph[i]){
cout<<v<<" ";
}
cout<<endl;
}*/
rep(i,0,V+H){
visited[i]=false;
}
int ans=0;
rep(i,0,V+H){
if(!visited[i]){
size=0;
independent=0;
DFS(i,0);
ans+=max(independent,size-independent);
}
}
cout<<ans<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
23804 KB |
Output is correct |
2 |
Correct |
24 ms |
23804 KB |
Output is correct |
3 |
Correct |
23 ms |
23800 KB |
Output is correct |
4 |
Correct |
24 ms |
23800 KB |
Output is correct |
5 |
Correct |
24 ms |
23800 KB |
Output is correct |
6 |
Correct |
24 ms |
23928 KB |
Output is correct |
7 |
Correct |
23 ms |
23800 KB |
Output is correct |
8 |
Correct |
24 ms |
23800 KB |
Output is correct |
9 |
Correct |
24 ms |
23800 KB |
Output is correct |
10 |
Correct |
24 ms |
23800 KB |
Output is correct |
11 |
Correct |
24 ms |
23800 KB |
Output is correct |
12 |
Correct |
23 ms |
23800 KB |
Output is correct |
13 |
Correct |
23 ms |
23800 KB |
Output is correct |
14 |
Correct |
23 ms |
23800 KB |
Output is correct |
15 |
Correct |
23 ms |
23800 KB |
Output is correct |
16 |
Correct |
24 ms |
23800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
23804 KB |
Output is correct |
2 |
Correct |
24 ms |
23804 KB |
Output is correct |
3 |
Correct |
23 ms |
23800 KB |
Output is correct |
4 |
Correct |
24 ms |
23800 KB |
Output is correct |
5 |
Correct |
24 ms |
23800 KB |
Output is correct |
6 |
Correct |
24 ms |
23928 KB |
Output is correct |
7 |
Correct |
23 ms |
23800 KB |
Output is correct |
8 |
Correct |
24 ms |
23800 KB |
Output is correct |
9 |
Correct |
24 ms |
23800 KB |
Output is correct |
10 |
Correct |
24 ms |
23800 KB |
Output is correct |
11 |
Correct |
24 ms |
23800 KB |
Output is correct |
12 |
Correct |
23 ms |
23800 KB |
Output is correct |
13 |
Correct |
23 ms |
23800 KB |
Output is correct |
14 |
Correct |
23 ms |
23800 KB |
Output is correct |
15 |
Correct |
23 ms |
23800 KB |
Output is correct |
16 |
Correct |
24 ms |
23800 KB |
Output is correct |
17 |
Correct |
23 ms |
23800 KB |
Output is correct |
18 |
Correct |
23 ms |
23800 KB |
Output is correct |
19 |
Correct |
24 ms |
23928 KB |
Output is correct |
20 |
Correct |
23 ms |
23928 KB |
Output is correct |
21 |
Correct |
24 ms |
23928 KB |
Output is correct |
22 |
Correct |
24 ms |
23928 KB |
Output is correct |
23 |
Correct |
24 ms |
23800 KB |
Output is correct |
24 |
Correct |
23 ms |
23800 KB |
Output is correct |
25 |
Correct |
24 ms |
23800 KB |
Output is correct |
26 |
Correct |
24 ms |
23800 KB |
Output is correct |
27 |
Correct |
24 ms |
23928 KB |
Output is correct |
28 |
Correct |
24 ms |
23956 KB |
Output is correct |
29 |
Correct |
23 ms |
23928 KB |
Output is correct |
30 |
Correct |
24 ms |
23928 KB |
Output is correct |
31 |
Correct |
24 ms |
23928 KB |
Output is correct |
32 |
Correct |
28 ms |
23800 KB |
Output is correct |
33 |
Correct |
24 ms |
23928 KB |
Output is correct |
34 |
Incorrect |
24 ms |
23800 KB |
Output isn't correct |
35 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
23804 KB |
Output is correct |
2 |
Correct |
24 ms |
23804 KB |
Output is correct |
3 |
Correct |
23 ms |
23800 KB |
Output is correct |
4 |
Correct |
24 ms |
23800 KB |
Output is correct |
5 |
Correct |
24 ms |
23800 KB |
Output is correct |
6 |
Correct |
24 ms |
23928 KB |
Output is correct |
7 |
Correct |
23 ms |
23800 KB |
Output is correct |
8 |
Correct |
24 ms |
23800 KB |
Output is correct |
9 |
Correct |
24 ms |
23800 KB |
Output is correct |
10 |
Correct |
24 ms |
23800 KB |
Output is correct |
11 |
Correct |
24 ms |
23800 KB |
Output is correct |
12 |
Correct |
23 ms |
23800 KB |
Output is correct |
13 |
Correct |
23 ms |
23800 KB |
Output is correct |
14 |
Correct |
23 ms |
23800 KB |
Output is correct |
15 |
Correct |
23 ms |
23800 KB |
Output is correct |
16 |
Correct |
24 ms |
23800 KB |
Output is correct |
17 |
Correct |
23 ms |
23800 KB |
Output is correct |
18 |
Correct |
23 ms |
23800 KB |
Output is correct |
19 |
Correct |
24 ms |
23928 KB |
Output is correct |
20 |
Correct |
23 ms |
23928 KB |
Output is correct |
21 |
Correct |
24 ms |
23928 KB |
Output is correct |
22 |
Correct |
24 ms |
23928 KB |
Output is correct |
23 |
Correct |
24 ms |
23800 KB |
Output is correct |
24 |
Correct |
23 ms |
23800 KB |
Output is correct |
25 |
Correct |
24 ms |
23800 KB |
Output is correct |
26 |
Correct |
24 ms |
23800 KB |
Output is correct |
27 |
Correct |
24 ms |
23928 KB |
Output is correct |
28 |
Correct |
24 ms |
23956 KB |
Output is correct |
29 |
Correct |
23 ms |
23928 KB |
Output is correct |
30 |
Correct |
24 ms |
23928 KB |
Output is correct |
31 |
Correct |
24 ms |
23928 KB |
Output is correct |
32 |
Correct |
28 ms |
23800 KB |
Output is correct |
33 |
Correct |
24 ms |
23928 KB |
Output is correct |
34 |
Incorrect |
24 ms |
23800 KB |
Output isn't correct |
35 |
Halted |
0 ms |
0 KB |
- |