Submission #442237

#TimeUsernameProblemLanguageResultExecution timeMemory
442237Vladth11Dango Maker (JOI18_dango_maker)C++14
100 / 100
558 ms143368 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <long double, pii> muchie;
typedef tree <ll, null_type, less_equal <ll>, rb_tree_tag, tree_order_statistics_node_update> OST;

const ll NMAX = 300001;
const ll INF = (1LL << 60);
const ll HALF = (1LL << 59);
const ll MOD = 1000000007;
const ll BLOCK = 318;
const ll base = 31;
const ll nr_of_bits = 21;
const ll LIMIT = 1000;

char mat[3002][3002];
int dp[3002][3002][3];
int n, m;
bool abil[3001][3001][3];

void bagadp(int i, int j){
    while(i >= 1 && i <= n && j >= 1 && j <= m){
        dp[i][j][0] = max({dp[i - 1][j + 1][1], dp[i - 1][j + 1][0], dp[i - 1][j + 1][2]});
        dp[i][j][1] = max({dp[i - 1][j + 1][1], dp[i - 1][j + 1][0]}) + 1;
        dp[i][j][2] = max({dp[i - 1][j + 1][2], dp[i - 1][j + 1][0]}) + 1;
        if(!abil[i][j][1])
            dp[i][j][1] = -2e9;
        if(!abil[i][j][2])
            dp[i][j][2] = -2e9;
        i++;
        j--;
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int i, j;
    cin >> n >> m;
    for(i = 1; i <= n; i++){
        for(j = 1; j <= m; j++){
            cin >> mat[i][j];
        }
    }
    for(i = 1; i <= n; i++){
        for(j = 1; j <= m; j++){
               abil[i][j][0] = 1;
            if(mat[i][j] != 'G')
                continue;
            if(mat[i][j - 1] == 'R' && mat[i][j + 1] == 'W')
                abil[i][j][1] = 1;
            if(mat[i - 1][j] == 'R' && mat[i + 1][j] == 'W')
                abil[i][j][2] = 1;
        }
    }
    for(j = 1; j <= m; j++){
        bagadp(1, j);
    }
    for(i = 1; i <= n; i++){
        bagadp(i, m);
    }
    int sum = 0;

    for(i = 1; i <= n; i++){
        sum += max({dp[i][1][0], dp[i][1][1], dp[i][1][2]});
    }
    for(i = 2; i <= m; i++){
        sum += max({dp[n][i][0], dp[n][i][1], dp[n][i][2]});
    }
    cout << sum;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...