#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[3000000];
int size;
bool visited2[3000];
int independent;
vector<int> graph[3000000];
vector<int> tree[3000];
short int DP[3000][2];
vector<int> cmp;
vector<int> graph2[3000];
void DFS(int node){
visited[node]=true;
cmp.push_back(node);
trav(v,graph[node]){
if(!visited[v]){
//tree[node].push_back(v);
DFS(v);
}
}
}
void DFS2(int node){
visited2[node]=true;
trav(v,graph2[node]){
if(!visited2[v]){
tree[node].push_back(v);
DFS2(v);
}
}
}
int BS(int lo, int hi, int target){
int mid=(hi+lo)/2;
if(cmp[mid]==target)return mid;
if(cmp[mid]<target)return BS(mid+1,hi,target);
if(cmp[mid]>target)return BS(lo,mid-1,target);
}
int compute(int node, int x){
//cout<<node<<"C"<<x<<endl;
if(DP[node][x]!=-1)return DP[node][x];
DP[node][x]=0;
if(x==0){
trav(v,tree[node]){
DP[node][x]+=max(compute(v,0),compute(v,1));
}
return DP[node][x];
}
DP[node][x]++;
trav(v,tree[node]){
DP[node][x]+=compute(v,0);
}
return DP[node][x];
}
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){
visited[i]=false;
}
int ans=0;
rep(i,0,V+H){
if(!visited[i]){
DFS(i);
sort(cmp.begin(),cmp.end());
rep(i,0,cmp.size()){
visited2[i]=false;
}
rep(i,0,cmp.size()){
DP[i][0]=-1;
DP[i][1]=-1;
}
//cout<<cmp.size()<<endl;
/*trav(x,cmp)cout<<x<<endl;
cout<<endl;*/
trav(x,cmp){
trav(y,graph[x]){
//cout<<BS(0,cmp.size()-1,x)<<"A "<<BS(0,cmp.size()-1,y)<<endl;
graph2[BS(0,cmp.size()-1,x)].push_back(BS(0,cmp.size()-1,y));
}
}
DFS2(0);
/*while(!q.empty()){
//if(q.front()<V)cout<<v[q.front()].first<<","<<v[q.front()].second<<" ";
//if(q.front()>=V)cout<<h[q.front()-V].first<<","<<h[q.front()-V].second<<" ";
visited[q.front()]=false;
q.pop();
}//cout<<endl;*/
//cout<<compute(0,0)<<" "<<compute(0,1)<<endl;
ans+=max(compute(0,0),compute(0,1));
rep(i,0,cmp.size()){
graph2[i].clear();
tree[i].clear();
}
cmp.clear();
//cout<<independent<<" "<<size-independent<<"A"<<endl;
}
}
/*rep(i,0,V+H){
cout<<compute(i,0)<<" "<<compute(i,1)<<endl;
}*/
cout<<ans<<endl;
return 0;
}
Compilation message
dango_maker.cpp: In function 'int main()':
dango_maker.cpp:6:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define rep(i,a,b) for(int i=a;i<b;i++)
dango_maker.cpp:122:11:
rep(i,0,cmp.size()){
~~~~~~~~~~~~~~
dango_maker.cpp:122:7: note: in expansion of macro 'rep'
rep(i,0,cmp.size()){
^~~
dango_maker.cpp:6:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define rep(i,a,b) for(int i=a;i<b;i++)
dango_maker.cpp:125:11:
rep(i,0,cmp.size()){
~~~~~~~~~~~~~~
dango_maker.cpp:125:7: note: in expansion of macro 'rep'
rep(i,0,cmp.size()){
^~~
dango_maker.cpp:6:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define rep(i,a,b) for(int i=a;i<b;i++)
dango_maker.cpp:149:11:
rep(i,0,cmp.size()){
~~~~~~~~~~~~~~
dango_maker.cpp:149:7: note: in expansion of macro 'rep'
rep(i,0,cmp.size()){
^~~
dango_maker.cpp: In function 'int BS(int, int, int)':
dango_maker.cpp:47:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
68 ms |
71032 KB |
Output is correct |
2 |
Correct |
67 ms |
70904 KB |
Output is correct |
3 |
Correct |
68 ms |
70900 KB |
Output is correct |
4 |
Correct |
67 ms |
70940 KB |
Output is correct |
5 |
Correct |
68 ms |
71032 KB |
Output is correct |
6 |
Correct |
68 ms |
71032 KB |
Output is correct |
7 |
Correct |
68 ms |
70904 KB |
Output is correct |
8 |
Correct |
67 ms |
71032 KB |
Output is correct |
9 |
Correct |
68 ms |
70876 KB |
Output is correct |
10 |
Correct |
67 ms |
70904 KB |
Output is correct |
11 |
Correct |
68 ms |
71032 KB |
Output is correct |
12 |
Correct |
68 ms |
70904 KB |
Output is correct |
13 |
Correct |
67 ms |
70944 KB |
Output is correct |
14 |
Correct |
67 ms |
70952 KB |
Output is correct |
15 |
Correct |
66 ms |
70904 KB |
Output is correct |
16 |
Correct |
67 ms |
70904 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
68 ms |
71032 KB |
Output is correct |
2 |
Correct |
67 ms |
70904 KB |
Output is correct |
3 |
Correct |
68 ms |
70900 KB |
Output is correct |
4 |
Correct |
67 ms |
70940 KB |
Output is correct |
5 |
Correct |
68 ms |
71032 KB |
Output is correct |
6 |
Correct |
68 ms |
71032 KB |
Output is correct |
7 |
Correct |
68 ms |
70904 KB |
Output is correct |
8 |
Correct |
67 ms |
71032 KB |
Output is correct |
9 |
Correct |
68 ms |
70876 KB |
Output is correct |
10 |
Correct |
67 ms |
70904 KB |
Output is correct |
11 |
Correct |
68 ms |
71032 KB |
Output is correct |
12 |
Correct |
68 ms |
70904 KB |
Output is correct |
13 |
Correct |
67 ms |
70944 KB |
Output is correct |
14 |
Correct |
67 ms |
70952 KB |
Output is correct |
15 |
Correct |
66 ms |
70904 KB |
Output is correct |
16 |
Correct |
67 ms |
70904 KB |
Output is correct |
17 |
Correct |
68 ms |
70976 KB |
Output is correct |
18 |
Correct |
67 ms |
70904 KB |
Output is correct |
19 |
Correct |
67 ms |
71032 KB |
Output is correct |
20 |
Correct |
67 ms |
70904 KB |
Output is correct |
21 |
Correct |
67 ms |
71032 KB |
Output is correct |
22 |
Correct |
67 ms |
70980 KB |
Output is correct |
23 |
Correct |
67 ms |
71032 KB |
Output is correct |
24 |
Correct |
83 ms |
71032 KB |
Output is correct |
25 |
Correct |
67 ms |
70904 KB |
Output is correct |
26 |
Correct |
68 ms |
70908 KB |
Output is correct |
27 |
Correct |
67 ms |
71032 KB |
Output is correct |
28 |
Correct |
67 ms |
70920 KB |
Output is correct |
29 |
Correct |
67 ms |
71032 KB |
Output is correct |
30 |
Correct |
68 ms |
70956 KB |
Output is correct |
31 |
Correct |
68 ms |
70968 KB |
Output is correct |
32 |
Correct |
67 ms |
71032 KB |
Output is correct |
33 |
Correct |
67 ms |
71020 KB |
Output is correct |
34 |
Correct |
67 ms |
70908 KB |
Output is correct |
35 |
Correct |
67 ms |
71032 KB |
Output is correct |
36 |
Correct |
67 ms |
71032 KB |
Output is correct |
37 |
Correct |
67 ms |
70980 KB |
Output is correct |
38 |
Correct |
68 ms |
71032 KB |
Output is correct |
39 |
Correct |
68 ms |
71032 KB |
Output is correct |
40 |
Correct |
67 ms |
71032 KB |
Output is correct |
41 |
Correct |
66 ms |
70904 KB |
Output is correct |
42 |
Correct |
67 ms |
70904 KB |
Output is correct |
43 |
Correct |
67 ms |
70896 KB |
Output is correct |
44 |
Correct |
66 ms |
70972 KB |
Output is correct |
45 |
Correct |
70 ms |
71032 KB |
Output is correct |
46 |
Correct |
67 ms |
71004 KB |
Output is correct |
47 |
Correct |
66 ms |
70904 KB |
Output is correct |
48 |
Correct |
67 ms |
70912 KB |
Output is correct |
49 |
Correct |
67 ms |
70908 KB |
Output is correct |
50 |
Correct |
67 ms |
70928 KB |
Output is correct |
51 |
Correct |
68 ms |
70992 KB |
Output is correct |
52 |
Correct |
83 ms |
70904 KB |
Output is correct |
53 |
Correct |
69 ms |
70968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
68 ms |
71032 KB |
Output is correct |
2 |
Correct |
67 ms |
70904 KB |
Output is correct |
3 |
Correct |
68 ms |
70900 KB |
Output is correct |
4 |
Correct |
67 ms |
70940 KB |
Output is correct |
5 |
Correct |
68 ms |
71032 KB |
Output is correct |
6 |
Correct |
68 ms |
71032 KB |
Output is correct |
7 |
Correct |
68 ms |
70904 KB |
Output is correct |
8 |
Correct |
67 ms |
71032 KB |
Output is correct |
9 |
Correct |
68 ms |
70876 KB |
Output is correct |
10 |
Correct |
67 ms |
70904 KB |
Output is correct |
11 |
Correct |
68 ms |
71032 KB |
Output is correct |
12 |
Correct |
68 ms |
70904 KB |
Output is correct |
13 |
Correct |
67 ms |
70944 KB |
Output is correct |
14 |
Correct |
67 ms |
70952 KB |
Output is correct |
15 |
Correct |
66 ms |
70904 KB |
Output is correct |
16 |
Correct |
67 ms |
70904 KB |
Output is correct |
17 |
Correct |
68 ms |
70976 KB |
Output is correct |
18 |
Correct |
67 ms |
70904 KB |
Output is correct |
19 |
Correct |
67 ms |
71032 KB |
Output is correct |
20 |
Correct |
67 ms |
70904 KB |
Output is correct |
21 |
Correct |
67 ms |
71032 KB |
Output is correct |
22 |
Correct |
67 ms |
70980 KB |
Output is correct |
23 |
Correct |
67 ms |
71032 KB |
Output is correct |
24 |
Correct |
83 ms |
71032 KB |
Output is correct |
25 |
Correct |
67 ms |
70904 KB |
Output is correct |
26 |
Correct |
68 ms |
70908 KB |
Output is correct |
27 |
Correct |
67 ms |
71032 KB |
Output is correct |
28 |
Correct |
67 ms |
70920 KB |
Output is correct |
29 |
Correct |
67 ms |
71032 KB |
Output is correct |
30 |
Correct |
68 ms |
70956 KB |
Output is correct |
31 |
Correct |
68 ms |
70968 KB |
Output is correct |
32 |
Correct |
67 ms |
71032 KB |
Output is correct |
33 |
Correct |
67 ms |
71020 KB |
Output is correct |
34 |
Correct |
67 ms |
70908 KB |
Output is correct |
35 |
Correct |
67 ms |
71032 KB |
Output is correct |
36 |
Correct |
67 ms |
71032 KB |
Output is correct |
37 |
Correct |
67 ms |
70980 KB |
Output is correct |
38 |
Correct |
68 ms |
71032 KB |
Output is correct |
39 |
Correct |
68 ms |
71032 KB |
Output is correct |
40 |
Correct |
67 ms |
71032 KB |
Output is correct |
41 |
Correct |
66 ms |
70904 KB |
Output is correct |
42 |
Correct |
67 ms |
70904 KB |
Output is correct |
43 |
Correct |
67 ms |
70896 KB |
Output is correct |
44 |
Correct |
66 ms |
70972 KB |
Output is correct |
45 |
Correct |
70 ms |
71032 KB |
Output is correct |
46 |
Correct |
67 ms |
71004 KB |
Output is correct |
47 |
Correct |
66 ms |
70904 KB |
Output is correct |
48 |
Correct |
67 ms |
70912 KB |
Output is correct |
49 |
Correct |
67 ms |
70908 KB |
Output is correct |
50 |
Correct |
67 ms |
70928 KB |
Output is correct |
51 |
Correct |
68 ms |
70992 KB |
Output is correct |
52 |
Correct |
83 ms |
70904 KB |
Output is correct |
53 |
Correct |
69 ms |
70968 KB |
Output is correct |
54 |
Correct |
67 ms |
71032 KB |
Output is correct |
55 |
Correct |
77 ms |
83192 KB |
Output is correct |
56 |
Correct |
69 ms |
71160 KB |
Output is correct |
57 |
Correct |
76 ms |
79352 KB |
Output is correct |
58 |
Correct |
157 ms |
87760 KB |
Output is correct |
59 |
Correct |
837 ms |
172112 KB |
Output is correct |
60 |
Correct |
832 ms |
172048 KB |
Output is correct |
61 |
Correct |
828 ms |
172020 KB |
Output is correct |
62 |
Correct |
67 ms |
71032 KB |
Output is correct |
63 |
Correct |
859 ms |
171512 KB |
Output is correct |
64 |
Runtime error |
1089 ms |
262144 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
65 |
Halted |
0 ms |
0 KB |
- |