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 <iostream>
#include <string.h>
using namespace std;
const int maxN = 3e3 + 326;
string mp[maxN];
int N, M, dp[maxN][maxN][4], ans[maxN * 2], r;
bool canV[maxN][maxN], canH[maxN][maxN];
int main(){
cin >> N >> M;
for(int i = 0; i < N; i++){
cin >> mp[i];
}
//for(int i = 0; i < N; i++) for(int j = 0; j < M; j++) cout << mp[i][j] << " \n"[j == M - 1];
for(int i = 0; i < N; i++){
for(int j = 0; j < M; j++){
canV[i][j] = i < N - 2 && (mp[i][j] == 'R' && mp[i + 1][j] == 'G' && mp[i + 2][j] == 'W');
canH[i][j] = j < M - 2 && (mp[i][j] == 'R' && mp[i][j + 1] == 'G' && mp[i][j + 2] == 'W');
if(i - 1 < 0 || j + 1 >= M){
dp[i][j][2] = (canV[i][j]);
dp[i][j][0] = (canH[i][j]);
ans[i + j] = max(ans[i + j], dp[i][j][2]);
ans[i + j] = max(ans[i + j], dp[i][j][0]);
//cout << "dp[" << i << "][" << j << "][" << 0 << "] = " << dp[i][j][0] << endl;
//cout << "dp[" << i << "][" << j << "][" << 2 << "] = " << dp[i][j][2] << endl;
} else {
dp[i][j][0] = max(max(dp[i - 1][j + 1][1], dp[i - 1][j + 1][0]), canH[i][j] * (dp[i - 1][j + 1][0] + 1));
dp[i][j][1] = max(dp[i - 1][j + 1][2], dp[i - 1][j + 1][3]);
if(canV[i][j]){
dp[i][j][2] = max(dp[i - 1][j + 1][0], dp[i - 1][j + 1][1]) + 1;
dp[i][j][3] = max(dp[i - 1][j + 1][2], dp[i - 1][j + 1][3]) + 1;
}
for(int k = 0; k < 3; k++){
ans[i + j] = max(ans[i + j], dp[i][j][k]);
//cout << "dp[" << i << "][" << j << "][" << k << "] = " << dp[i][j][k] << endl;
}
}
}
}
/*
for(int i = 0; i < N; i++) for(int j = 0; j < M; j++) cout << canV[i][j] << " \n"[j == M - 1];
cout << endl;
for(int i = 0; i < N; i++) for(int j = 0; j < M; j++) cout << canH[i][j] << " \n"[j == M - 1];
cout << endl;
*/
for(int i = 0; i < N + M; i++) r += ans[i];
cout << r << 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... |