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<iostream>
#include<stdio.h>
#include<vector>
#include<cmath>
#include<queue>
#include<string.h>
#include<map>
#include<set>
#include<algorithm>
#define ll long long
#define pi pair < ll,ll >
#define mp(a,b) make_pair(a,b)
#define rep(i,a,b) for(int i = a;i < b;i++)
#define N 3004
#define INF 1e9+7
using namespace std;
ll n,m,ans;
char ar[N][N];
ll dp[N][3]; // dp[.][1] = chose up in last row
bool can(pi r,pi g,pi w)
{
if(w.first < 0 || w.first >= n || w.second < 0 || w.second >= m)
return false;
return (ar[r.first][r.second] == 'R' && ar[g.first][g.second] == 'G' && ar[w.first][w.second] == 'W');
}
int main()
{
ios_base::sync_with_stdio(false);
cin >> n >> m;
rep(i,0,n)
{
rep(j,0,m)
{
cin >> ar[i][j];
}
}
rep(s,0,n+m-1)
{
memset(dp,0,sizeof dp);
ll j = min(m-1,(ll)s);
ll i = s - j;
dp[i][0] = 0;
if(can(mp(i-1,j),mp(i,j),mp(i+1,j)))
{
dp[i][1] = 1;
}
if(can(mp(i,j-1),mp(i,j),mp(i,j+1)))
{
dp[i][2] = 1;
}
i++;
j--;
while(i <= s && j >= 0)
{
dp[i][0] = max(dp[i-1][1],dp[i-1][2]);
dp[i][1] = max(dp[i-1][0],dp[i-1][1]) + (ll)(can(mp(i-1,j),mp(i,j),mp(i+1,j)));
dp[i][2] = max(dp[i-1][0],dp[i-1][2]) + (ll)(can(mp(i,j-1),mp(i,j),mp(i,j+1)));
i++;
j--;
}
i--;
j++;
ans += max(dp[i][0],max(dp[i][1],dp[i][2]));
}
cout << ans << endl;
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... |