답안 #503138

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
503138 2022-01-07T11:02:04 Z Kirill_Maglysh Dango Maker (JOI18_dango_maker) C++17
0 / 100
1 ms 216 KB
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>

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

using namespace std;

typedef long long ll;

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

ll readLL();

string readStr();

void resolve();

bool check(const vector<string> &field, 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();
    vector<string> field(height);
    for (int i = 0; i < height; ++i) {
        field[i] = readStr();
    }

    vector<vector<vector<ll>>> dp(height, vector<vector<ll>>(width, vector<ll>(3, 0)));
    ll res = 0;
    for (int i = 0; i < height; ++i) {
        for (int j = 0; j < width; ++j) {
            ll prevHor = 0;
            ll prevEmp = 0;
            ll prevVer = 0;
            if (i > 0 && j > 0) {
                prevHor = dp[i - 1][j - 1][HORIZONTAL];
                prevVer = dp[i - 1][j - 1][VERTICAL];
                prevEmp = dp[i - 1][j - 1][EMPTY];
            }

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

            if (i > 0 && i < height - 1 && check(field, i, j, VERTICAL)) {
                dp[i][j][VERTICAL] = 1 + max(prevVer, prevEmp);
            }

            if (j > 0 && j < width - 1 && check(field, i, j, HORIZONTAL)) {
                dp[i][j][HORIZONTAL] = 1 + max(prevHor, prevEmp);
            }

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

    printLn(res);
}

bool check(const vector<string> &field, 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 216 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Incorrect 0 ms 204 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 216 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Incorrect 0 ms 204 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 216 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Incorrect 0 ms 204 KB Output isn't correct
7 Halted 0 ms 0 KB -