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 ll long long
#define ar array
const int mxN = 3005, M = 1e9+7;
int n, m, dp[3][mxN], ans = 0;
string s[mxN];
inline bool c(int x, int y, char c){
return x>=0&&x<n&&y>=0&&y<m&&s[x][y]==c;
}
int main(){
#ifdef _DEBUG
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0);
cin >> n >> m;
for(int i = 0; i<n; ++i){
cin >> s[i];
}
for(int i = 0; i<n+m-3; ++i){
int border = min(m, i+2);
for(int j = 0; j<border; ++j){
dp[0][j+1] = max(dp[0][j], max(dp[1][j], dp[2][j]));
if(c(i-j+1, j-1, 'R') && c(i-j+1, j, 'G') && c(i-j+1, j+1, 'W')){
dp[1][j+1] = max(dp[0][j], dp[1][j])+1;
}else{
dp[1][j+1] = 0;
}
if(c(i-j, j, 'R') && c(i-j+1, j, 'G') && c(i-j+2, j, 'W')){
dp[2][j+1] = max(dp[0][j], dp[2][j])+1;
}else{
dp[2][j+1] = 0;
}
}
ans += max(dp[0][border], max(dp[1][border], dp[2][border]));
}
cout << ans << "\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... |