# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1128989 | LeonaRaging | Dango Maker (JOI18_dango_maker) | C++20 | 279 ms | 115292 KiB |
#include<bits/stdc++.h>
using namespace std;
const int N = 3005;
int n, m, dp[N][N][3];
string s[N];
bool ok_row(int i, int j) {
return (j > 1 && j < m && s[i][j - 1] == 'R' && s[i][j] == 'G' && s[i][j + 1] == 'W');
}
bool ok_col(int i, int j) {
return (i > 1 && i < n && s[i - 1][j] == 'R' && s[i][j] == 'G' && s[i + 1][j] == 'W');
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (fopen(".INP", "r")) {
freopen(".INP", "r", stdin);
freopen(".OUT", "w", stdout);
}
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> s[i], s[i] = ' ' + s[i];
int res = 0;
for (int S = 2; S <= n + m; S++) {
for (int i = min(n, S - 1); i >= max(1, S - m); i--) {
int j = S - i;
dp[i][j][0] = max({dp[i + 1][j - 1][0], dp[i + 1][j - 1][1], dp[i + 1][j - 1][2]});
if (ok_row(i, j))
dp[i][j][1] = max({dp[i + 1][j - 1][0], dp[i + 1][j - 1][1]}) + 1;
if (ok_col(i, j))
dp[i][j][2] = max({dp[i + 1][j - 1][0], dp[i + 1][j - 1][2]}) + 1;
res -= max({dp[i + 1][j - 1][0], dp[i + 1][j - 1][1], dp[i + 1][j - 1][2]});
res += max({dp[i][j][0], dp[i][j][1], dp[i][j][2]});
}
}
cout << res;
}
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... |