Submission #531193

# Submission time Handle Problem Language Result Execution time Memory
531193 2022-02-28T04:35:56 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;

constexpr int nax = 105;
char mat[nax][nax];
const string str = "RGW";
priority_queue<array<int, 4>, vector<array<int, 4>>, greater<array<int, 4>>> q;


bool check_ok(int i, int j, int p) {
    string curr;
    if (p == 0) {
        for(int k = 0; k < 3 && j+k < nax; k++) {
            curr += mat[i][j+k];
        }
    }
    else {
        for(int k = 0; k < 3 && i+k < nax; 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 && j+k < nax; k++) {
            cnt += check_ok(i, j+k, 0);
            cnt += check_ok(i, j+k, 1);
        }
    }
    else {
        for(int k = 0; k < 3 && i+k < nax; k++) {
            cnt += check_ok(i+k, j, 0);
            cnt += check_ok(i+k, j, 1);
        }
    }
    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 cnt(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 cnt = 0;
    for(int x = 0; x < nax; x++) {
        for(int y = 0; y < nax; y++)  {
            cnt += check_ok(x, y, 0);
            cnt += check_ok(x, y, 1);
        }
    }

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


    return cnt;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    assert(n < nax && m < nax);

    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++) {
            if (check_ok(i, j, 0)) {
                int cnt = thru(i, j, 0);
//                cout << i << " " << j << " 0 " << cnt << "\n";
                q.push({cnt, i, j, 0});
            }
            if (check_ok(i, j, 1)) {
                int cnt = thru(i, j, 1);
//                cout << i << " " << j << " 1 " << cnt << "\n";
                q.push({cnt, i, j, 1});
            }
        }
    }

    int ans = 0;

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

        int x = v[1], y = v[2], p = v[3];

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

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


//    while(1) {
//        bool ok = false;
//        int best = -1, x = -1, y = -1, p = -1;
//
//        for(int i = 0; i < nax; i++) {
//            for(int j = 0; j < nax; j++) {
//                if (check_ok(i, j, 0)) {
//                    ok = true;
//                    int curr = cnt(i, j, 0);
//                    if (curr > best) {
//                        best = curr;
//                        x = i, y = j, p = 0;
//                    }
//                }
//                if (check_ok(i, j, 1)) {
//                    ok = true;
//                    int curr = cnt(i, j, 1);
//                    if (curr > best) {
//                        best = curr;
//                        x = i, y = j, p = 1;
//                    }
//                }
//
//            }
//        }
//
//        if (!ok) break;
//        rem(x, y, p);
////        cout << x << " " << y << " " << p << "\n";
//        ans++;
//    }

    cout << ans << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 312 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 312 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 312 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 312 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 1 ms 312 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 316 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Incorrect 1 ms 204 KB Output isn't correct
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 312 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 312 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 1 ms 312 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 316 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Incorrect 1 ms 204 KB Output isn't correct
23 Halted 0 ms 0 KB -