# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
79395 | Sherazin | Dango Maker (JOI18_dango_maker) | C++14 | 295 ms | 37276 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 = 3e3+5;
int n, m, ans;
char A[N][N];
bool valid[N][N][2];
int main() {
scanf("%d %d", &n, &m);
for(int i = 1; i <= n; i++) scanf(" %s", A[i]+1);
for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) {
if(A[i][j] != 'G') continue;
if(i > 1 && i < n && A[i-1][j] == 'R' && A[i+1][j] == 'W') valid[i][j][0] = true;
if(j > 1 && j < m && A[i][j-1] == 'R' && A[i][j+1] == 'W') valid[i][j][1] = true;
}
for(int sum = 2; sum <= n+m; sum++) {
int dp[2][3], lst = 0;
fill_n(dp[0], 2*3, 0);
for(int i = 1; i < sum && i <= n; i++) {
int j = sum-i, now = i & 1, pre = now^1;
dp[now][0] = max({ dp[pre][0], dp[pre][1], dp[pre][2] });
if(valid[i][j][0]) dp[now][1] = max(dp[pre][0], dp[pre][1]) + 1;
if(valid[i][j][1]) dp[now][2] = max(dp[pre][0], dp[pre][2]) + 1;
lst = i;
}
ans += max({ dp[lst & 1][0], dp[lst & 1][1], dp[lst & 1][2] });
}
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... |