# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1134574 | Pekiban | Dango Maker (JOI18_dango_maker) | C++17 | 0 ms | 320 KiB |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
char a[n+1][m+1];
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
cin >> a[i][j];
}
}
int H[n+1][m+1][2];
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
H[i][j][0] = (j >= 2 && a[i][j] == 'G' && a[i][j-1] == 'R' && a[i][j+1] == 'W');
H[i][j][1] = (i >= 2 && a[i][j] == 'G' && a[i-1][j] == 'R' && a[i+1][j] == 'W');
}
}
int ans = 0;
for (int k = 2; k <= n+m; k++) {
int dp[k][3], t = 0; // 1 za vertikalne (1), 2 za horizontalne (0);
for (int i = 0; i < k; ++i) dp[i][0] = dp[i][1] = dp[i][2] = 0;
for (int i = 1; i < k; ++i) {
if (k-i <= 0 || k-i > m || i > n) continue;
dp[i][0] = max({dp[i-1][0], dp[i-1][1], dp[i-1][2]});
dp[i][1] = H[i][k-i][1] + max({dp[i-1][0], dp[i-1][1]});
dp[i][2] = H[i][k-i][0] + max({dp[i-1][0], dp[i-1][2]});
t = max({t, dp[i][0], dp[i][1], dp[i][2]});
}
ans += t;
delete dp;
}
cout << ans << '\n';
}
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... |