Submission #503226

# Submission time Handle Problem Language Result Execution time Memory
503226 2022-01-07T14:38:01 Z Kirill_Maglysh Dango Maker (JOI18_dango_maker) C++17
0 / 100
191 ms 262148 KB
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>

#define printLn(n) cout << n << '\n'

using namespace std;

typedef int ll;

vector<vector<char>> field(3000 + 2, vector<char>(3000 + 2, '#'));
vector<vector<vector<ll>>> dp(3000 + 2, vector<vector<ll>>(3000 + 2, vector<ll>(3, 0)));

const ll EMPTY = 0;
const ll HORIZONTAL = 1;
const ll VERTICAL = 2;

ll readLL();

string readStr();

void resolve();

bool check(ll i, ll j, ll dir);

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    resolve();

    return 0;
}

void resolve() {
    ll height = readLL();
    ll width = readLL();
    for (ll i = 1; i <= height; ++i) {
        string str = readStr();
        for (ll j = 1; j <= width; ++j) {
            field[i][j] = str[j - 1];
        }
    }

    ll res = 0;
    for (ll i = 1; i <= height; ++i) {
        for (ll j = 1; j <= width; ++j) {
            ll prevHor = dp[i - 1][j + 1][HORIZONTAL];
            ll prevVer = dp[i - 1][j + 1][VERTICAL];
            ll prevEmp = dp[i - 1][j + 1][EMPTY];

            dp[i][j][EMPTY] = max(prevEmp, max(prevHor, prevVer));

            if (check(i, j, VERTICAL)) {
                dp[i][j][VERTICAL] = 1 + max(prevVer, prevEmp);
            }

            if (check(i, j, HORIZONTAL)) {
                dp[i][j][HORIZONTAL] = 1 + max(prevHor, prevEmp);
            }

            if (i == height || j == 1) {
                res += max(dp[i][j][EMPTY], max(dp[i][j][HORIZONTAL], dp[i][j][VERTICAL]));
            }
        }
    }

    printLn(res);
}

bool check(ll i, ll j, ll dir) {
    if (dir == HORIZONTAL) {
        return (field[i][j - 1] == 'R' && field[i][j] == 'G' && field[i][j + 1] == 'W');
    } else if (dir == VERTICAL) {
        return (field[i - 1][j] == 'R' && field[i][j] == 'G' && field[i + 1][j] == 'W');
    }

    return false;
}

ll readLL() {
    ll num;
    cin >> num;
    return num;
}

string readStr() {
    string num;
    cin >> num;
    return num;
}
# Verdict Execution time Memory Grader output
1 Runtime error 191 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 191 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 191 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -