This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define ll long long
const int MAX=1e3+10;
int n, m, dp[MAX][3][3];
pair<bool, bool>t[MAX][MAX];
char c[MAX][MAX];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin>>n>>m;
for(int i=1; i<=n; i++)
for(int j=1; j<=m; j++)
cin>>c[i][j];
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
t[i][j].fi=(i+2<=n && c[i][j]=='R' && c[i+1][j]=='G' && c[i+2][j]=='W');
t[i][j].se=(j+2<=m && c[i][j]=='R' && c[i][j+1]=='G' && c[i][j+2]=='W');
}
}
int wyn=0;
for(int i=1; i<=n+m-1; i++){
int sx, sy;
if(i<=n) sx=i, sy=1;
else sx=n, sy=i-n+1;
for(int x=sx, y=sy, l=1; x>=1&&y<=m; x--, y++, l++){
for(int i1=0; i1<=2; i1++)
for(int i2=0; i2<=2; i2++)
dp[l][0][i1]=max(dp[l][0][i1], dp[l-1][i1][i2]);
if(t[x][y].fi){
for(int i1=0; i1<2; i1++)
for(int i2=0; i2<2; i2++)
dp[l][1][i1]=max(dp[l][1][i1], dp[l-1][i1][i2]+1);
}
if(t[x][y].se){
for(int i1=0; i1<=2; i1++)
for(int i2=0; i2<=2; i2++)
dp[l][2][i1]=max(dp[l][2][i1], dp[l-1][i1][i2]+1);
}
if(x==1||y==m){
int maxi=0;
for(int i1=0; i1<=2; i1++)
for(int i2=0; i2<=2; i2++)
maxi=max(maxi, dp[l][i1][i2]);
wyn+=maxi;
}
}
for(int x=sx, y=sy, l=1; x>=1&&y<=m; x--, y++, l++)
for(int i1=0; i1<=2; i1++)
for(int i2=0; i2<=2; i2++)
dp[l][i1][i2]=0;
}
cout<<wyn<<"\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |