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 MX = 3005;
int dango[MX][MX];
char a[MX][MX];
int dp[MX][3];
int n, m;
void PlayGround() {
cin>>n>>m;
for(int i=1; i<=n; ++i) {
for(int j=1; j<=m; ++j) {
cin>>a[i][j];
}
}
for(int i=1; i<=n; ++i) {
for(int j=1; j<=m; ++j) {
if(i+2<=n && a[i][j]=='R' && a[i+1][j]=='G' && a[i+2][j]=='W') {
dango[i][j] |= 1;
}
if(j+2<=m && a[i][j]=='R' && a[i][j+1]=='G' && a[i][j+2]=='W') {
dango[i][j] |= 2;
}
}
}
int ans = 0;
for(int S=2; S<=n+m; ++S) {
memset(dp, 0, sizeof dp);
int mx = 0;
for(int i=n; i>0; --i) if(S-i>=1 && S-i<=m) {
if(dango[i][S-i]&1) {
dp[i][0] = 1+dp[i+1][2];
}
if(dango[i][S-i]&2) {
dp[i][0] = max(dp[i][0], 1+dp[i+1][0]);
}
dp[i][0] = max(dp[i][0], dp[i+1][0]);
for(int res : {1, 2}) {
dp[i][res] = dp[i+1][res-1];
if(dango[i][S-i]&1) {
dp[i][res] = max(dp[i][res], 1+dp[i+1][2]);
}
}
mx = max(mx, *max_element(dp[i], dp[i]+3));
}
ans += mx;
}
cout<<ans<<'\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
PlayGround();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |