제출 #376556

#제출 시각아이디문제언어결과실행 시간메모리
376556astoriaDango Maker (JOI18_dango_maker)C++14
13 / 100
24 ms35712 KiB
#include "bits/stdc++.h" using namespace std; const int N=3005,M=3005; //vector<pair<pair<int,int>,int> > g[N][M][2]; //j=0,i=1; bool is[N][M][2]; bool vis[N][M][2]; pair<int,int> dfs(int x, int y, int k){ if(vis[x][y][k]) return {0,0}; vis[x][y][k] = 1; pair<int,int> an; if(k==0) an={1,0}; else an={0,1}; int tk; if(k==0) tk=1; else tk=0; if(is[x][y][tk]){ pair<int,int> their = dfs(x,y,tk); an.first += their.first; an.second += their.second; } if(is[x-1][y+1][tk]){ pair<int,int> their = dfs(x-1,y+1,tk); an.first += their.first; an.second += their.second; } if(is[x+1][y-1][tk]){ pair<int,int> their = dfs(x+1,y-1,tk); an.first += their.first; an.second += their.second; } return an; /*pair<int,int> an; if(k==0) an={1,0}; else an={0,1}; for(auto ii : g[x][y][k]){ pair<int,int> their = dfs(ii.first.first,ii.first.second,ii.second); an.first += their.first; an.second += their.second; } return an;*/ } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n,m; cin>>n>>m; char grid[n+5][m+5]; for(int i=0; i<=n+1; i++){ for(int j=0; j<=m+1; j++){ grid[i][j]='p'; } } for(int i=1; i<=n; i++){ for(int j=1; j<=m; j++){ cin>>grid[i][j]; } } memset(is,0,sizeof(is)); for(int i=1; i<=n; i++){ for(int j=1; j<=m; j++){ if(grid[i][j]!='G') continue; if(grid[i][j-1]=='R'&&grid[i][j+1]=='W'){ is[i][j][0]=1; } if(grid[i-1][j]=='R'&&grid[i+1][j]=='W'){ is[i][j][1]=1; } } } /* for(int i=1; i<=n; i++){ for(int j=1; j<=m; j++){ if(!is[i][j][0]) continue; if(is[i][j][1]){ g[i][j][0].push_back({{i,j},1}); } if(is[i-1][j+1][1]){ g[i][j][0].push_back({{i-1,j+1},1}); } if(is[i+1][j-1][1]){ g[i][j][0].push_back({{i+1,j-1},1}); } } } for(int i=1; i<=n; i++){ for(int j=1; j<=m; j++){ if(!is[i][j][1]) continue; if(is[i][j][0]){ g[i][j][1].push_back({{i,j},0}); } if(is[i-1][j+1][0]){ g[i][j][1].push_back({{i-1,j+1},0}); } if(is[i+1][j-1][0]){ g[i][j][1].push_back({{i+1,j-1},0}); } } }*/ //cout<<"HEY"<<endl; memset(vis,0,sizeof(vis)); int tot=0; for(int i=1; i<=n; i++){ for(int j=1; j<=m; j++){ if(is[i][j][0]&&!vis[i][j][0]){ pair<int,int> an = dfs(i,j,0); tot += max(an.first,an.second); } if(is[i][j][1]&&!vis[i][j][1]){ pair<int,int> an = dfs(i,j,1); tot += max(an.first,an.second); } } } cout<<tot; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...