Submission #1276626

#TimeUsernameProblemLanguageResultExecution timeMemory
1276626tm.khoa.tmDango Maker (JOI18_dango_maker)C++20
100 / 100
548 ms221544 KiB
//I love ManchesterUnited
#include<bits/stdc++.h>
using namespace std;

#define love ManchesterUnited
#define int long long
#define pb push_back
#define FOR(i,a,b) for (int i=(a); i<=(b); i++)
#define FORD(i,b,a) for (int i=(b); i>=(a); i--)
#define REP(i, n) for(int i=0; i<(n); ++i)
#define RED(i, n) for(int i=(n)-1; i>=0; --i)
#define time() cerr << endl << "-------------Time:" << 1000.0 * clock() / CLOCKS_PER_SEC << "ms.";
#define ALL(a) (a).begin(),(a).end()
#define ii pair<int,int>
#define iii pair<int,ii>
#define fi first
#define se second
#define endl '\n'
#define MASK(x) (1 << (x))
#define BIT(mask,i) ((mask >> i) & 1)
typedef long long ll;
#define MOD 1000000007
#define INF 1000000000000000000LL

template<class X, class Y>
    bool minimize(X &x, const Y &y) {
        if (x > y) {
            x = y;
            return true;
        } else return false;
    }
template<class X, class Y>
    bool maximize(X &x, const Y &y) {
        if (x < y) {
            x = y;
            return true;
        } else return false;
    }
template<class T>
    T Abs(const T &x) {
        return (x < 0 ? -x : x);
    }

//___________________________________________________________________________________________________________________________________________________________
// CODE:

const int N = 3005;
int n, m;
char a[N][N];
int dp[N][N][3];

bool can(int x, int y, char c) {
    if (x < 1 || x > n || y < 1 || y > m) return false;
    return a[x][y] == c;
}

int f(int x, int y, int t) {
    if (x < 1 || x > n || y < 1 || y > m) return 0;

    int &res = dp[x][y][t];
    if (res != -1) return res;

    int add = 0;
    if (t == 1 && can(x, y - 1, 'R') && can(x, y, 'G') && can(x, y + 1, 'W')) add = 1;
    if (t == 2 && can(x - 1, y, 'R') && can(x, y, 'G') && can(x + 1, y, 'W')) add = 1;

    if (t != 0 && add == 0) return res = 0;

    res = 0;
    FOR(i, 0, 2) {
        if (t + i == 3) continue;
        maximize(res, f(x - 1, y + 1, i) + add);
    }
    return res;
}

int32_t main(){
//    freopen("test.inp","r",stdin);
//    freopen("test.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    cin >> n >> m;
    memset(dp, -1, sizeof(dp));
    FOR(i, 1, n) FOR(j,1,m) cin >> a[i][j];

    int ans = 0;
    FOR(i, 1, n)
        ans += max({f(i, 1, 0), f(i, 1, 1), f(i, 1, 2)});
    FOR(i, 2, m)
        ans += max({f(n, i, 0), f(n, i, 1), f(n, i, 2)});

    cout << ans << endl;
    time();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...