Submission #529747

# Submission time Handle Problem Language Result Execution time Memory
529747 2022-02-23T15:00:24 Z zxcvbnm Dango Maker (JOI18_dango_maker) C++14
13 / 100
1 ms 332 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const string str = "RGW";
constexpr int nax = 3005;
int thru[nax][nax][2];
char mat[nax][nax];

priority_queue<array<int, 4>, vector<array<int, 4>>, greater<array<int, 4>>> q;

int thrus(int x, int y, int p) {
    return thru[x][y][p];
}

void push_in(int x, int y, int p) {
    q.push({thrus(x, y, p), x, y, p});
}

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

bool check_ok(int i, int j, int p) {
    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);
}

void go(int i, int j, int p, bool rec, bool rem=false) {
    if (!rem)
        if (!check_ok(i, j, p)) return;

//    cout << "go: " << i << " " << j << " " << p << "\n";

    if (p == 0) {
        int cnt = 0;
        if (check_ok(i, j, 1^rem)) {
            cnt++;
            if (rec) {
                go(i, j, 1^rem, false);
            }
        }
        if (i-1 >= 0 && check_ok(i-1, j+1, 1^rem)) {
            cnt++;
            if (rec) {
                go(i-1, j+1, 1^rem, false);
            }
        }
        if (i-2 >= 0 && check_ok(i-2, j+2, 1^rem)) {
            cnt++;
            if (rec) {
                go(i-2, j+2, 1^rem, false);
            }
        }

        if (!rem) {
            thru[i][j][0] = cnt;
            q.push({cnt, i, j, 0});
        }
//                cout << i << " " << j << " " << 0 << " " << cnt << "\n";
    }
    if (p == 1) {
        int cnt = 0;
        if (check_ok(i, j, 0^rem)) {
            cnt++;
            if (rec) {
                go(i, j, 0^rem, false);
            }
        }
        if (j-1 >= 0 && check_ok(i+1, j-1, 0^rem)) {
            cnt++;
            if (rec) {
                go(i+1, j-1, 0^rem, false);
            }
        }
        if (j-2 >= 0 && check_ok(i+2, j-2, 0^rem)) {
            cnt++;
            if (rec) {
                go(i+2, j-2, 0^rem, false);
            }
        }

        if (!rem) {
            thru[i][j][1] = cnt;
            q.push({cnt, i, j, 1});
        }
//                cout << i << " " << j << " " << 1 << " " << cnt << "\n";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            cin >> mat[i][j];
        }
    }

    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            go(i, j, 0, false);
            go(i, j, 1, false);
        }
    }

    int ans = 0;

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

        if (!check_ok(v[1], v[2], v[3])) continue;
        ans++;

        rem(v[1], v[2], v[3]);
        go(v[1], v[2], v[3], true, true);
//        cout << v[0] << " " << v[1] << " " << v[2] << " " << v[3] << "\n";
    }

    cout << ans << "\n";
//    for(int i = 0; i < n; i++) {
//        for(int j = 0; j < m-2; j++) {
//            string curr;
//            for(int k = 0; k < 3; k++) {
//                curr += mat[i][j+k];
//            }
//
//            if (curr == str) {
//                ok[i][j][0] = true;
//            }
//        }
//    }
//
//    for(int j = 0; j < m; j++) {
//        for(int i = 0; i < n-2; i++) {
//            string curr;
//            for(int k = 0; k < 3; k++) {
//                curr += mat[i+k][j];
//            }
//
//            if (curr == str) {
//                ok[i][j][1] = true;
//            }
//        }
//    }
//
//    for(int i = 0; i < n; i++) {
//        for(int j = 0; j < m; j++) {
//            if (ok[i][j][0]) {
//                int cnt = 0;
//                cnt += ok[i][j][1];
//                if (i-1 >= 0) {
//                    cnt += ok[i-1][j+1][1];
//                }
//                if (i-2 >= 0) {
//                    cnt += ok[i-2][j+2][1];
//                }
//
//                thru[i][j][0] = cnt;
//                q.push({cnt, i, j, 0});
////                cout << i << " " << j << " " << 0 << " " << cnt << "\n";
//            }
//            if (ok[i][j][1]) {
//                int cnt = 0;
//                cnt += ok[i][j][0];
//                if (j-1 >= 0) {
//                    cnt += ok[i+1][j-1][0];
//                }
//                if (j-2 >= 0) {
//                    cnt += ok[i+2][j-2][0];
//                }
//
//                thru[i][j][1] = cnt;
//                q.push({cnt, i, j, 1});
////                cout << i << " " << j << " " << 1 << " " << cnt << "\n";
//            }
//        }
//    }
//
//    int ans = 0;
//    while(!q.empty()) {
//        auto v = q.top();
//        q.pop();
//        cout << v[0] << " " << v[1] << " " << v[2] << " " << v[3] << "\n";
//        ok[v[1]][v[2]][v[3]] = false;
//        int i = v[1], j = v[2];
//
//        if (v[3] == 0) {
//            string curr;
//            for(int k = 0; k < 3; k++) {
//                curr += mat[v[1]][v[2]+k];
//            }
//            if (curr != str) continue;
//            ans++;
//            for(int k = 0; k < 3; k++) {
//                mat[v[1]][v[2]+k] = 'X';
//            }
//
//            if (ok[i][j][1]) {
//                thru[i][j][1]--;
//                push_in(i, j, 1);
//            }
//            if (i-1 >= 0 && ok[i-1][j+1][1]) {
//                thru[i-1][j+1][1]--;
//                push_in(i-1, j+1, 1);
//            }
//            if (i-2 >= 0 && ok[i-2][j+2][1]) {
//                thru[i-2][j+2][1]--;
//                push_in(i-2, j+2, 1);
//            }
//        }
//        else {
//            string curr;
//            for(int k = 0; k < 3; k++) {
//                curr += mat[v[1]+k][v[2]];
//            }
//            if (curr != str) continue;
//            ans++;
//            for(int k = 0; k < 3; k++) {
//                mat[v[1]+k][v[2]] = 'X';
//            }
//
//            if (ok[i][j][0]) {
//                thru[i][j][0]--;
//                push_in(i, j, 0);
//            }
//            if (j-1 >= 0 && ok[i+1][j-1][0]) {
//                thru[i+1][j-1][0]--;
//                push_in(i+1, j-1, 0);
//            }
//            if (j-2 >= 0 && ok[i+2][j-2][0]) {
//                thru[i+2][j-2][0]--;
//                push_in(i+2, j-2, 0);
//            }
//        }
////        cout << v[0] << "\n";
//    }
//
//    cout << ans << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 324 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 324 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 0 ms 324 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 0 ms 332 KB Output is correct
22 Correct 1 ms 324 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 0 ms 332 KB Output is correct
25 Correct 1 ms 300 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Incorrect 1 ms 332 KB Output isn't correct
29 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 324 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 0 ms 324 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 0 ms 332 KB Output is correct
22 Correct 1 ms 324 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 0 ms 332 KB Output is correct
25 Correct 1 ms 300 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Incorrect 1 ms 332 KB Output isn't correct
29 Halted 0 ms 0 KB -