Submission #209396

#TimeUsernameProblemLanguageResultExecution timeMemory
209396kshitij_sodaniDango Maker (JOI18_dango_maker)C++17
13 / 100
154 ms262148 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[3001][3001][2]; //int vis[3001][3001][2]; int dp[3001][3001][2][2];//1 take 0 not take int it[3001][3001]; int n,m; void dfs(int i,int j,int kk,int mm=-1,int nn=-1,int pp=-1){ dp[i][j][kk][0]=0; dp[i][j][kk][1]=0; if(kk==0){ if(it[i][j]==0 and it[i+1][j]==1 and it[i+2][j]==2){ dp[i][j][kk][1]=1; if(j<m-2 ){ if(i==mm and j==nn and 1-kk==pp){ } else{ dfs(i,j,1-kk,i,j,kk); dp[i][j][kk][1]+=dp[i][j][1-kk][0]; dp[i][j][kk][0]+=dp[i][j][1-kk][1]; } } if(j<m-1 and j>0){ if(i+1==mm and j-1==nn and 1-kk==pp){ } else{ dfs(i+1,j-1,1-kk,i,j,kk); dp[i][j][kk][1]+=dp[i+1][j-1][1-kk][0]; dp[i][j][kk][0]+=dp[i+1][j-1][1-kk][1]; } } if(j>1){ if(i+2==mm and j-2==nn and 1-kk==pp){ } else{ dfs(i+2,j-2,1-kk,i,j,kk); dp[i][j][kk][1]+=dp[i+2][j-2][1-kk][0]; dp[i][j][kk][0]+=dp[i+2][j-2][1-kk][1]; } } } } if(kk==1){ if(it[i][j]==0 and it[i][j+1]==1 and it[i][j+2]==2){ dp[i][j][kk][1]=1; //cout<<i<<" "<<j<<" "<<0<<endl; if(i<n-2){ if(i==mm and j==nn and 1-kk==pp){ } else{ dfs(i,j,1-kk,i,j,kk); dp[i][j][kk][1]+=dp[i][j][1-kk][0]; dp[i][j][kk][0]+=dp[i][j][1-kk][1]; } } if(i<n-1 and i>0){ if(i-1==mm and j+1==nn and 1-kk==pp){ } else{ dfs(i-1,j+1,1-kk,i,j,kk); dp[i][j][kk][1]+=dp[i-1][j+1][1-kk][0]; dp[i][j][kk][0]+=dp[i-1][j+1][1-kk][1]; } } if(i>1){ if(i-2==mm and j+2==nn and 1-kk==pp){ } else{ dfs(i-2,j+2,1-kk,i,j,kk); dp[i][j][kk][1]+=dp[i-2][j+2][1-kk][0]; dp[i][j][kk][0]+=dp[i-2][j+2][1-kk][1]; } } } } dp[i][j][kk][1]=max(dp[i][j][kk][1],dp[i][j][kk][0]); // assert(dp[i][j][kk][1]>=0); } int main(){ ios_base::sync_with_stdio(false); // memset(vis,1,sizeof(vis)); cin.tie(NULL); char s; cin>>n>>m; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ for(int k=0;k<2;k++){ dp[i][j][k][1]=-1; dp[i][j][k][0]=-1; } } } //int it[n][m]; memset(it,3,sizeof(it)); 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 ii=0;ii<n;ii++){ for(int jj=0;jj<m;jj++){ if(dp[ii][jj][0][0]==-1 and ii<n-2){ dfs(ii,jj,0); ans+=dp[ii][jj][0][1]; } if(dp[ii][jj][1][0]==-1 and jj<m-2){ dfs(ii,jj,1); ans+=dp[ii][jj][1][1]; } } } cout<<ans<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...