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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;
char a[3011][3011];
bool valright(int x, int y)
{
if(a[x][y]=='R'&&a[x][y+1]=='G'&&a[x][y+2]=='W')
{
return 1;
}
else return 0;
}
bool valdown(int x, int y)
{
if(a[x][y]=='R'&&a[x+1][y]=='G'&&a[x+2][y]=='W')
{
return 1;
}
else return 0;
}
int good[3011][3011];
int dp[6111][3];
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
int n,m; cin>>n>>m;
for(int i=0;i<n;i++)
{
cin>>a[i];
}
int ans=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(valright(i,j))
{
good[i][j+1]^=1;
}
if(valdown(i,j))
{
good[i+1][j]^=2;
}
}
}
for(int sum=0;sum<=n+m-2;sum++)
{
int res=0; bool st=0;
for(int i=0;i<n;i++)
{
if(sum-i<0||sum-i>=m) continue;
if(!st)
{
dp[i][0]=dp[i][1]=dp[i][2]=0;
if(good[i][sum-i]&1) dp[i][1]=1;
if(good[i][sum-i]&2) dp[i][2]=1;
st=1;
res=max(res,max(dp[i][0],max(dp[i][1],dp[i][2])));
continue;
}
dp[i][0] = max(dp[i-1][0], max(dp[i-1][1], dp[i-1][2]));
dp[i][1]=dp[i][2]=0;
if(good[i][sum-i]&1)
{
dp[i][1] = 1;
if(i>0) dp[i][1] += max(dp[i-1][0], dp[i-1][1]);
}
if(good[i][sum-i]&2)
{
dp[i][2] = 1;
if(i>0) dp[i][2] += max(dp[i-1][0], dp[i-1][2]);
}
res=max(res,max(dp[i][0],max(dp[i][1],dp[i][2])));
}
ans+=res;
}
cout<<ans<<'\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |