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;
int n, m, ans;
int dp[MAXN][3];
char a[MAXN][MAXN];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
{
cin >> a[i][j];
}
}
for(int i = 2; i <= 2 * n; i++)
{
int nw = 0;
for(int j = 1; j <= min(n, i); j++)
{
for(int k = 0; k < 3; k++)
{
dp[j][k] = 0;
}
}
for(int j = 1; j <= min(n, i); j++)
{
int posx = j, posy = i - j;
if(a[posx][posy] == 'R' and a[posx][posy + 1] == 'G' and a[posx][posy + 2] == 'W')
{
dp[j][0] = max(dp[j][0], dp[j - 1][0] + 1);
}
if(a[posx][posy] == 'R' and a[posx + 1][posy] == 'G' and a[posx + 2][posy] == 'W')
{
dp[j][2] = max(dp[j][2], max({dp[j - 1][0], dp[j - 1][1], dp[j - 1][2]}) + 1);
}
dp[j][0] = max(dp[j][0], dp[j - 1][1]);
dp[j][1] = max(dp[j][1], dp[j - 1][2]);
nw = max({nw, dp[j][0], dp[j][1], dp[j][2]});
}
ans += nw;
}
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... |