답안 #531224

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
531224 2022-02-28T05:23:16 Z zxcvbnm Dango Maker (JOI18_dango_maker) C++14
33 / 100
2000 ms 164104 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

constexpr int nax = 3005;
char mat[nax][nax];
int thrus[nax][nax][2];
const string str = "RGW";
vector<array<int, 3>> s[10];
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];
        }
    }

    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);
                thrus[i][j][0] = cnt;
//                cout << i << " " << j << " 0 " << cnt << "\n";
                s[cnt].push_back({i, j, 0});
            }
            if (check_ok(i, j, 1)) {
                int cnt = thru(i, j, 1);
//                cout << i << " " << j << " 1 " << cnt << "\n";
                thrus[i][j][1] = cnt;
                s[cnt].push_back({i, j, 1});
            }
        }
    }

    int ans = 0;

    for(int rep = 0; rep < 10; rep++) {
        while(!s[rep].empty()) {
            auto v = s[rep].back();
            s[rep].pop_back();

            int x = v[0], y = v[1], p = v[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);
                        if (cnt < thrus[i][j][0]) {
                            thrus[i][j][0] = cnt;
                            if (cnt < rep) {
                                rep = cnt;
                            }
                            s[cnt].push_back({i, j, 0});
                        }
                    }
                    if (check_ok(i, j, 1)) {
                        int cnt = thru(i, j, 1);
                        if (cnt < thrus[i][j][1]) {
                            thrus[i][j][1] = cnt;
                            if (cnt < rep) {
                                rep = cnt;
                            }
                            s[cnt].push_back({i, j, 1});
                        }
                    }
                }
            }
        }
    }

    cout << ans << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 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 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 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 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 0 ms 332 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 0 ms 332 KB Output is correct
25 Correct 0 ms 332 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 0 ms 332 KB Output is correct
28 Correct 0 ms 332 KB Output is correct
29 Correct 0 ms 332 KB Output is correct
30 Correct 0 ms 332 KB Output is correct
31 Correct 0 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 0 ms 332 KB Output is correct
34 Correct 0 ms 332 KB Output is correct
35 Correct 0 ms 332 KB Output is correct
36 Correct 0 ms 332 KB Output is correct
37 Correct 0 ms 332 KB Output is correct
38 Correct 0 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 0 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 0 ms 332 KB Output is correct
46 Correct 0 ms 332 KB Output is correct
47 Correct 0 ms 332 KB Output is correct
48 Correct 0 ms 332 KB Output is correct
49 Correct 0 ms 332 KB Output is correct
50 Correct 1 ms 332 KB Output is correct
51 Correct 1 ms 332 KB Output is correct
52 Correct 1 ms 332 KB Output is correct
53 Correct 0 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 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 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 0 ms 332 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 0 ms 332 KB Output is correct
25 Correct 0 ms 332 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 0 ms 332 KB Output is correct
28 Correct 0 ms 332 KB Output is correct
29 Correct 0 ms 332 KB Output is correct
30 Correct 0 ms 332 KB Output is correct
31 Correct 0 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 0 ms 332 KB Output is correct
34 Correct 0 ms 332 KB Output is correct
35 Correct 0 ms 332 KB Output is correct
36 Correct 0 ms 332 KB Output is correct
37 Correct 0 ms 332 KB Output is correct
38 Correct 0 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 0 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 0 ms 332 KB Output is correct
46 Correct 0 ms 332 KB Output is correct
47 Correct 0 ms 332 KB Output is correct
48 Correct 0 ms 332 KB Output is correct
49 Correct 0 ms 332 KB Output is correct
50 Correct 1 ms 332 KB Output is correct
51 Correct 1 ms 332 KB Output is correct
52 Correct 1 ms 332 KB Output is correct
53 Correct 0 ms 332 KB Output is correct
54 Correct 1 ms 332 KB Output is correct
55 Correct 4 ms 9676 KB Output is correct
56 Correct 4 ms 460 KB Output is correct
57 Correct 11 ms 13416 KB Output is correct
58 Correct 212 ms 16144 KB Output is correct
59 Correct 1401 ms 90500 KB Output is correct
60 Correct 1404 ms 91456 KB Output is correct
61 Correct 1388 ms 91448 KB Output is correct
62 Correct 1 ms 332 KB Output is correct
63 Correct 1352 ms 91400 KB Output is correct
64 Execution timed out 2073 ms 164104 KB Time limit exceeded
65 Halted 0 ms 0 KB -