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;
const int mxN=3e3;
int n, m, dp[mxN+1][3], ans;
string g[mxN];
inline bool c(int i, int j, char c) {
return i>=0&&i<n&&j>=0&&j<m&&g[i][j]==c;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for(int i=0; i<n; ++i)
cin >> g[i];
for(int i=0; i<=n+m-4; ++i) {
int jm=min(m, i+2);
for(int j=0; j<jm; ++j) {
dp[j+1][0]=max(dp[j][0], max(dp[j][1], dp[j][2]));
dp[j+1][1]=c(i+1-j, j-1, 'R')&&c(i+1-j, j, 'G')&&c(i+1-j, j+1, 'W')?max(dp[j][0], dp[j][1])+1:0;
dp[j+1][2]=c(i-j, j, 'R')&&c(i+1-j, j, 'G')&&c(i+2-j, j, 'W')?max(dp[j][0], dp[j][2])+1:0;
}
// cout << max(dp[jm][0], max(dp[jm][1], dp[jm][2])) << endl;
ans+=max(dp[jm][0], max(dp[jm][1], dp[jm][2]));
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |