Submission #917709

#TimeUsernameProblemLanguageResultExecution timeMemory
917709NinedesuDango Maker (JOI18_dango_maker)C++14
100 / 100
116 ms141908 KiB
#include<bits/stdc++.h> using namespace std; const int N=3002; int n,m; int ans; int dp[N][N][3]; bool vis[N][N][3]; string s[N]; int main(){ ios_base::sync_with_stdio(0),cin.tie(0); cin >> n >> m; for(int i=1; i<=n; i++){ cin >> s[i]; s[i]="x"+s[i]; } for(int i=1; i<=n; i++){ for(int j=1; j<=m; j++){ if(s[i][j]=='G'){ if(j>1&&s[i][j-1]=='R'&&j<m&&s[i][j+1]=='W'){ if(!vis[i-1][j+1][1])dp[i][j][1]=dp[i-1][j+1][0]+dp[i-1][j+1][1]+1; else dp[i][j][1]=max(dp[i-1][j+1][0],dp[i-1][j+1][1]+1); vis[i][j][1]=true; } if(i>1&&s[i-1][j]=='R'&&i<n&&s[i+1][j]=='W'){ if(!vis[i-1][j+1][2])dp[i][j][2]=dp[i-1][j+1][0]+dp[i-1][j+1][2]+1; else dp[i][j][2]=max(dp[i-1][j+1][0],dp[i-1][j+1][2]+1); vis[i][j][2]=true; } } dp[i][j][0]=max(dp[i-1][j+1][0],max(dp[i-1][j+1][2],dp[i-1][j+1][1])); } dp[i][0][0]=max(dp[i-1][1][0],max(dp[i-1][1][2],dp[i-1][1][1])); for(int j=0; j<=m; j++){ dp[n+1][j][0]=max(dp[n][j+1][0],max(dp[n][j+1][2],dp[n][j+1][1])); } } for(int i=1; i<=n+1; i++)ans+=dp[i][0][0]; for(int j=1; j<=m; j++)ans+=dp[n+1][j][0]; cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...