# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
103051 | tincamatei | Dango Maker (JOI18_dango_maker) | C++14 | 237 ms | 88704 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 MAX_N = 3000;
int dp[2][1+MAX_N+1][1+MAX_N+1];
char matr[1+MAX_N+1][1+MAX_N+1];
char getch(FILE *fin) {
char ch = fgetc(fin);
while(!isalpha(ch))
ch = fgetc(fin);
return ch;
}
int main() {
#ifdef HOME
FILE *fin = fopen("input.in", "r");
FILE *fout = fopen("output.out", "w");
#else
FILE *fin = stdin;
FILE *fout = stdout;
#endif
int n, m;
fscanf(fin, "%d%d", &n, &m);
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= m; ++j)
matr[i][j] = getch(fin);
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= m; ++j) {
dp[0][i][j] = max(dp[0][i - 1][j + 1], dp[1][i - 1][j + 1]);
dp[1][i][j] = dp[0][i][j];
if(matr[i][j] == 'G' && matr[i][j - 1] == 'R' && matr[i][j + 1] == 'W')
dp[0][i][j] = max(dp[0][i][j], dp[0][i - 1][j + 1] + 1);
if(matr[i][j] == 'G' && matr[i - 1][j] == 'R' && matr[i + 1][j] == 'W')
dp[1][i][j] = max(dp[1][i][j], dp[1][i - 1][j + 1] + 1);
}
int rez = 0;
for(int i = 1; i <= n; ++i)
rez = rez + max(dp[0][i][1], dp[1][i][1]);
for(int i = 2; i <= m; ++i)
rez = rez + max(dp[0][n][i], dp[1][n][i]);
fprintf(fout, "%d", rez);
fclose(fin);
fclose(fout);
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... |