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;
typedef long long ll;
const ll MOD = 1000000007;
#define x first
#define y second
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
ll n,m;
cin>>n>>m;
vector<vector<ll>> cad(n,vector<ll>(m,0));
for(int i=0; i<n; i++)
{
for(int j=0; j<m; j++)
{
char car;
cin>>car;
if(car=='R') cad[i][j]=1;
else if(car=='G') cad[i][j]=2;
else cad[i][j]=3;
}
}
ll cont=0;
for(int z=0; z<n; z++)
{
map<ll,ll> dp[2];
ll a=z,b=0;
ll i=0;
while(a>=0&&b<m)
{
dp[0][i]=max(dp[0][i],dp[0][i-1]);
dp[1][i]=max(dp[1][i],dp[1][i-1]);
if(a>=2) dp[0][i]=max(dp[0][i],max(dp[0][i-1],dp[1][i-3])+((cad[a][b]==3)&(cad[a-1][b]==2)&(cad[a-2][b]==1)));
if(b>=2) dp[1][i]=max(dp[1][i],max(dp[0][i-3],dp[1][i-1])+((cad[a][b]==3)&(cad[a][b-1]==2)&(cad[a][b-2]==1)));
a--;
b++;
i++;
}
cont+=max(dp[0][i-1],dp[1][i-1]);
}
for(int z=1; z<m; z++)
{
map<ll,ll> dp[2];
ll a=n-1,b=z;
ll i=0;
while(a>=0&&b<m)
{
dp[0][i]=max(dp[0][i],dp[0][i-1]);
dp[1][i]=max(dp[1][i],dp[1][i-1]);
if(a>=2) dp[0][i]=max(dp[0][i],max(dp[0][i-1],dp[1][i-3])+((cad[a][b]==3)&(cad[a-1][b]==2)&(cad[a-2][b]==1)));
if(b>=2) dp[1][i]=max(dp[1][i],max(dp[0][i-3],dp[1][i-1])+((cad[a][b]==3)&(cad[a][b-1]==2)&(cad[a][b-2]==1)));
a--;
b++;
i++;
}
cont+=max(dp[0][i-1],dp[1][i-1]);
}
cout<<cont;
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... |