# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
210418 | SamAnd | Dango Maker (JOI18_dango_maker) | C++17 | 164 ms | 18040 KiB |
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 N = 3003;
int n, m;
char a[N][N];
int dp[N][3];
int main()
{
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i)
scanf(" %s", (a[i] + 1));
int ans = 0;
for (int si = 1; si <= n; ++si)
{
memset(dp, 0, sizeof dp);
int x = si;
int y = 1;
for (int i = 1; ; ++i)
{
dp[i][0] = max(dp[i - 1][0], max(dp[i - 1][1], dp[i - 1][2]));
if (a[x][y - 1] == 'R' && a[x][y] == 'G' && a[x][y + 1] == 'W')
dp[i][1] = max(dp[i - 1][0], dp[i - 1][1]) + 1;
if (a[x - 1][y] == 'R' && a[x][y] == 'G' && a[x + 1][y] == 'W')
dp[i][2] = max(dp[i - 1][0], dp[i - 1][2]) + 1;
--x;
++y;
if (x == 0 || y == m + 1)
{
ans += max(dp[i][0], max(dp[i][1], dp[i][2]));
break;
}
}
}
for (int sj = 2; sj <= m; ++sj)
{
memset(dp, 0, sizeof dp);
int x = n;
int y = sj;
for (int i = 1; ; ++i)
{
dp[i][0] = max(dp[i - 1][0], max(dp[i - 1][1], dp[i - 1][2]));
if (a[x][y - 1] == 'R' && a[x][y] == 'G' && a[x][y + 1] == 'W')
dp[i][1] = max(dp[i - 1][0], dp[i - 1][1]) + 1;
if (a[x - 1][y] == 'R' && a[x][y] == 'G' && a[x + 1][y] == 'W')
dp[i][2] = max(dp[i - 1][0], dp[i - 1][2]) + 1;
--x;
++y;
if (x == 0 || y == m + 1)
{
ans += max(dp[i][0], max(dp[i][1], dp[i][2]));
break;
}
}
}
printf("%d\n", ans);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |