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 maxn = 3005;
using ll = long long;
char s[maxn][maxn];
int n, m;
ll dp[maxn][maxn][3];
ll corner[maxn + maxn];
int main(int argc, char const *argv[])
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= m; ++j){
cin >> s[i][j];
if(s[i][j] == 'R')s[i][j] = 'A';
else if(s[i][j] == 'G')s[i][j] = 'B';
else s[i][j] = 'C';
}
}
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= m; ++j){
dp[i][j][0] = max({dp[i - 1][j + 1][0], dp[i - 1][j + 1][1], dp[i - 1][j + 1][2]});
if(s[i][j] == 'B'){
if(s[i][j - 1] == 'A' && s[i][j + 1] == 'C'){
dp[i][j][1] = max({dp[i][j][1], dp[i - 1][j + 1][0] + 1, dp[i - 1][j + 1][1] + 1});
}
if(s[i + 1][j] == 'C' && s[i - 1][j] == 'A'){
dp[i][j][2] = max({dp[i][j][2], dp[i - 1][j + 1][0] + 1, dp[i - 1][j + 1][2] + 1});
}
}
corner[i + j] = max({corner[i + j], dp[i][j][1], dp[i][j][2], dp[i][j][0]});
}
}
ll ans = 0;
for(int i = 1; i <= n + m; ++i){
ans += corner[i];
}
cout << ans << '\n';
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... |