Submission #209397

#TimeUsernameProblemLanguageResultExecution timeMemory
209397kshitij_sodaniDango Maker (JOI18_dango_maker)C++17
33 / 100
6 ms504 KiB
#include <iostream> #include <bits/stdc++.h> using namespace std; #define mp make_pair #define pb push_back typedef long long int llo; #define a first #define b second #define endl "\n" vector<pair<pair<int,int>,int>> adj[20][20][2]; int vis[20][20][2]; int dp[20][20][2][2];//1 take 0 not take int dfs(int ii,int jj,int kk){ vis[ii][jj][kk]=1; dp[ii][jj][kk][1]=1; for(auto nn:adj[ii][jj][kk]){ int aa; int bb; int cc; aa=nn.a.a; bb=nn.a.b; cc=nn.b; if(vis[aa][bb][cc]==0){ dfs(aa,bb,cc); dp[ii][jj][kk][0]+=dp[aa][bb][cc][1]; dp[ii][jj][kk][1]+=dp[aa][bb][cc][0]; } } dp[ii][jj][kk][1]=max(dp[ii][jj][kk][1],dp[ii][jj][kk][0]); } int main(){ ios_base::sync_with_stdio(false); memset(vis,1,sizeof(vis)); cin.tie(NULL); memset(dp,0,sizeof(dp)); int n,m; char s; cin>>n>>m; int it[n][m]; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ cin>>s; if(s=='R'){ it[i][j]=0; } else if(s=='G'){ it[i][j]=1; } else{ it[i][j]=2; } // cout<<it[i][j]<<" "; } // cout<<endl; } int st=0; for(int i=0;i<n;i++){ for(int j=0;j<m-2;j++){ if(it[i][j]==0 and it[i][j+1]==1 and it[i][j+2]==2){ vis[i][j][1]=0; // cout<<i<<" "<<j<<" "<<1<<endl; } } } for(int i=0;i<n-2;i++){ for(int j=0;j<m;j++){ if(it[i][j]==0 and it[i+1][j]==1 and it[i+2][j]==2){ vis[i][j][0]=0; //cout<<i<<" "<<j<<" "<<0<<endl; if(j<m-2){ if(it[i][j+1]==1 and it[i][j+2]==2){ adj[i][j][0].pb(mp(mp(i,j),1)); adj[i][j][1].pb(mp(mp(i,j),0)); } } if(j<m-1 and j>0){ if(it[i+1][j-1]==0 and it[i+1][j+1]==2){ adj[i][j][0].pb(mp(mp(i+1,j-1),1)); adj[i+1][j-1][1].pb(mp(mp(i,j),0)); } } if(j>1){ if(it[i+2][j-2]==0 and it[i+2][j-1]==1){ adj[i][j][0].pb(mp(mp(i+2,j-2),1)); adj[i+2][j-2][1].pb(mp(mp(i,j),0)); } } } } } int ans=0; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ if(vis[i][j][0]==0){ dfs(i,j,0); ans+=dp[i][j][0][1]; } if(vis[i][j][1]==0){ dfs(i,j,1); ans+=dp[i][j][1][1]; } } } cout<<ans<<endl; return 0; }

Compilation message (stderr)

dango_maker.cpp: In function 'int dfs(int, int, int)':
dango_maker.cpp:30:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
dango_maker.cpp: In function 'int main()':
dango_maker.cpp:56:6: warning: unused variable 'st' [-Wunused-variable]
  int st=0;
      ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...