제출 #531208

#제출 시각아이디문제언어결과실행 시간메모리
531208zxcvbnmDango Maker (JOI18_dango_maker)C++14
33 / 100
1833 ms262148 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

constexpr int nax = 3005;
char mat[nax][nax];
const string str = "RGW";
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
int n, m;

bool check_ok(int i, int j, int p) {
    if (i < 0 || j < 0 || i >= n || j >= m) return false;

    string curr;
    if (p == 0) {
        for(int k = 0; k < 3; k++) {
            curr += mat[i][j+k];
        }
    }
    else {
        for(int k = 0; k < 3; k++) {
            curr += mat[i+k][j];
        }
    }
    return (curr == str);
}

int thru(int i, int j, int p) {
    int cnt = 0;
    if (p == 0) {
        for(int k = 0; k < 3; k++) {
            cnt += check_ok(i-k, j+k, 1);
        }
    }
    else {
        for(int k = 0; k < 3; k++) {
            cnt += check_ok(i+k, j-k, 0);
        }
    }
    return cnt;
}

void rem(int i, int j, int p) {
    if (p == 0) {
        for(int k = 0; k < 3; k++) {
            mat[i][j+k] = 'X';
        }
    }
    else {
        for(int k = 0; k < 3; k++) {
            mat[i+k][j] = 'X';
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> m;

    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            cin >> mat[i][j];
        }
    }

    vector<array<int, 3>> vec;

    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            if (check_ok(i, j, 0)) {
                int cnt = thru(i, j, 0);
//                cout << i << " " << j << " 0 " << cnt << "\n";
                q.push({cnt, vec.size()});
                vec.push_back({i, j, 0});
            }
            if (check_ok(i, j, 1)) {
                int cnt = thru(i, j, 1);
//                cout << i << " " << j << " 1 " << cnt << "\n";
                q.push({cnt, vec.size()});
                vec.push_back({i, j, 1});
            }
        }
    }

    int ans = 0;

    while(!q.empty()) {
        auto v = q.top();
        q.pop();

        int x = vec[v.second][0], y = vec[v.second][1], p = vec[v.second][2];

        if (!check_ok(x, y, p)) continue;
        ans++;
        rem(x, y, p);

        for(int i = max(0, x-3); i < min(n, x+3); i++) {
            for(int j = max(0, y-3); j < min(m, y+3); j++) {
                if (check_ok(i, j, 0)) {
                    int cnt = thru(i, j, 0);
                    q.push({cnt, vec.size()});
                    vec.push_back({i, j, 0});
                }
                if (check_ok(i, j, 1)) {
                    int cnt = thru(i, j, 1);
                    q.push({cnt, vec.size()});
                    vec.push_back({i, j, 1});
                }
            }
        }
    }

    cout << ans << "\n";
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...