Submission #678573

#TimeUsernameProblemLanguageResultExecution timeMemory
678573Tuanlinh123Dango Maker (JOI18_dango_maker)C++17
100 / 100
378 ms155500 KiB
#include<bits/stdc++.h>
#define ll int
#define ld long double
#define pll pair<ll,ll>
#define mp make_pair
#define pb push_back
#define fi first
#define se second

using namespace std;

#define LOCALIO "C:/Users/admin/Documents/Code/"
#define maxn 3100

ll n, m, crr;
char a[maxn][maxn];
ll dp[maxn][maxn][2][2];

bool check(ll i, ll j, ll di)
{
    if (di)
    {
        if (i+2>n || i<=0)
            return 0;
        if (a[i][j]!='R' || a[i+1][j]!='G' || a[i+2][j]!='W')
            return 0;
        return 1;
    }
    else
    {
        if (j+2>m || j<=0)
            return 0;
        if (a[i][j]!='R' || a[i][j+1]!='G' || a[i][j+2]!='W')
            return 0;
        return 1;
    }
}

int main()
{
    #ifdef LOCAL
        freopen( LOCALIO "input.txt","r",stdin) ;
        freopen( LOCALIO "output.txt","w",stdout) ;
    #endif

    ios_base::sync_with_stdio(NULL); cin.tie(nullptr); cout.tie(nullptr);
//	freopen("FIBONACCI.inp","r",stdin);
//	freopen("FIBONACCI.out","w",stdout);
    cin >> n >> m;
    for (ll i=1; i<=n; i++)
        for (ll j=1; j<=m; j++)
            cin >> a[i][j];
    ll ans=0;
    for (ll k=2; k<=n+m; k++)
    {
        ll Max=0;
        for (ll i=1; i<=n; i++)
        {
            ll j=k-i; 
            if (j<=0 || j>m)
                continue;
            dp[i][j][0][0]=max(dp[i-1][j+1][0][0], dp[i-1][j+1][0][1]);
            dp[i][j][0][1]=max(dp[i-1][j+1][1][0], dp[i-1][j+1][1][1]);
            if (check(i, j, 1))
                dp[i][j][1][0]=dp[i][j][0][0]+1, dp[i][j][1][1]=dp[i][j][0][1]+1;
            if (check(i, j, 0))
                dp[i][j][0][0]=max(dp[i][j][0][0], dp[i-1][j+1][0][0]+1);
            ll val=max(max(dp[i][j][0][0], dp[i][j][0][1]), max(dp[i][j][1][0], dp[i][j][1][1]));
            // cout << i << " " << j << " " << val << "\n";
            Max=max(Max, val);
        }
        ans+=Max;
    }
    cout << ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...