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>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define N 3005
using namespace std;
int n, m, ans, a[N][N], dp[N][N][3];
char c;
//dur = 0 hic koyma
//dur = 1 yatak
//dur = 2 dikey
int f(int i, int j, int dur){
if(i > n or j > m or i < 1 or j < 1)
return 0;
int &r = dp[i][j][dur];
if(r != -1)
return r;
int art = 0;
if(dur == 1)
if(a[i][j] == 2 and a[i][j - 1] == 1 and a[i][j + 1] == 3)
art = 1;
if(dur == 2)
if(a[i][j] == 2 and a[i - 1][j] == 1 and a[i + 1][j] == 3)
art = 1;
if(dur == 0)
r = max(f(i - 1, j + 1, 0), max(f(i - 1, j + 1, 1), f(i - 1, j + 1, 2)));
if(dur == 1)
r = max(f(i - 1, j + 1, 0), f(i - 1, j + 1, 1)) + art;
if(dur == 2)
r = max(f(i - 1, j + 1, 2), f(i - 1, j + 1, 0)) + art;
return r;
}
int main() {
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
memset(dp, -1, sizeof dp);
scanf("%d %d",&n ,&m);
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++){
scanf(" %c",&c);
if(c == 'R')
a[i][j] = 1;
if(c == 'G')
a[i][j] = 2;
if(c == 'W')
a[i][j] = 3;
}
for(int i = 1; i <= n; i++)
ans += max(f(i, 1, 0) , f(i, 1, 2));
for(int i = 2; i <= m; i++)
ans += max(f(n, i, 0) , f(n, i, 1));
printf("%d\n",ans);
return 0;
}
Compilation message (stderr)
dango_maker.cpp: In function 'int main()':
dango_maker.cpp:42:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&n ,&m);
~~~~~^~~~~~~~~~~~~~~~
dango_maker.cpp:45:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf(" %c",&c);
~~~~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |