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;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
const int N = 3005;
int ok[N][N];
char str[N][N];
int dp[N][3];
int n,m;
int main(void) {
cin>>n>>m;
for (int i = 1;i <= n;++i)
cin>>(str[i] + 1);
for (int i = 1;i <= n;++i)
for (int j = 1;j <= m;++j) {
if (str[i - 1][j] == 'R' && str[i][j] == 'G' && str[i + 1][j] == 'W')
ok[i][j] |= 1;
if (str[i][j - 1] == 'R' && str[i][j] == 'G' && str[i][j + 1] == 'W')
ok[i][j] |= 2;
}
int ans = 0;
for (int sum = 1;sum <= n + m;++sum) {
int rem = 0;
for (int i = 1;i <= n;++i)
for (int t = 0;t < 3;++t)
dp[i][t] = 0;
for (int i = 1;i <= n;++i) {
if (1 <= sum - i && sum - i <= m) {
if (ok[i][sum - i] & 1) {
smax(dp[i][1],1 + max(dp[i - 1][1],dp[i - 1][0]));
}
if (ok[i][sum - i] & 2) {
smax(dp[i][2],1 + max(dp[i - 1][2],dp[i - 1][0]));
}
smax(dp[i][0],max({dp[i - 1][0],dp[i - 1][1],dp[i - 1][2]}));
}
smax(rem,max({dp[i][0],dp[i][1],dp[i][2]}));
}
ans += rem;
}
cout << ans << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |