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>
#define f first
#define s second
#define pb push_back
using namespace std;
const int N=3005;
long long n,m,mx[2*N],dp[N][N][4],ans;;
char ch[N][N];
int check(int i, int j) {
if (ch[i][j]=='G' && ch[i][j-1]=='R' && ch[i][j+1]=='W') return 1;
else return 0;
}
int check1(int i, int j) {
if (ch[i][j]=='G' && ch[i-1][j]=='R' && ch[i+1][j]=='W') return 1;
else return 0;
}
int main() {
cin>>n>>m;
for (int i=1; i<=n; i++) {
for (int j=1; j<=m; j++) {
cin>>ch[i][j];
}
}
for (int i=1; i<=n; i++) {
for (int j=1; j<=m; j++) {
if (check(i,j)) {
dp[i][j][1]=max(dp[i-1][j+1][0],dp[i-1][j+1][1])+1;
//dp[i][j][1]=max(dp[i][j][1],dp[i-1][j+1][2]);
}
if (check1(i,j)){
dp[i][j][2]=max(dp[i-1][j+1][0],dp[i-1][j+1][2])+1;
//dp[i][j][2]=max(dp[i][j][1],dp[i-1][j+1][1]);
}
dp[i][j][0]=max(dp[i-1][j+1][0],max(dp[i-1][j+1][1],dp[i-1][j+1][2]));
mx[i+j]=max(mx[i+j], max(dp[i][j][0],max(dp[i][j][1],dp[i][j][2])));
}
}
for (int i=1; i<=n+m; i++) {
ans+=mx[i];
}
cout<<ans<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |