답안 #502453

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
502453 2022-01-06T03:37:46 Z zorianka Dango Maker (JOI18_dango_maker) C++17
100 / 100
1321 ms 244096 KB
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC optimize("fast-math")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

vector<vector<int>> L;
vector<int> matched;
vector<int> used;
vector<bool> da;
int cnt = 1;
int sz = 0;
int szR = 0;

bool dfs(int v) {
    if (used[v] == cnt) return false;
    used[v] = cnt;
    for (int u : L[v]) {
        auto &m = matched[u];
        if (matched[u] == -1 || dfs(m)) {
            matched[u] = v;
            da[v] = true;
            return true;
        }
    }
    return false;
}


void solve() {
    int n, m;
    cin >> n >> m;
    vector<string> d(n);
    vector<vector<int>> comp(n, vector<int>(m, -1));
    for (int i = 0; i < n; i++)
        cin >> d[i];
    for (int i = 0; i < n - 2; i++)
        for (int j = 0; j < m; j++) {
            if (d[i][j] == 'R' && d[i + 1][j] == 'G' && d[i + 2][j] == 'W') {
                comp[i][j] = comp[i + 1][j] = comp[i + 2][j] = sz++;
            }
        }
    L.resize(sz);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m - 2; j++) {
            if (d[i][j] == 'R' && d[i][j + 1] == 'G' && d[i][j + 2] == 'W') {
                int cur = szR++;
                for (int dj = 0; dj < 3; dj++) {
                    if (comp[i][j + dj] != -1) {
                        L[comp[i][j + dj]].push_back(cur);
                    }
                }
            }
        }
    }
    matched.resize(szR, -1);
    used.resize(sz);
    da.resize(sz);
    for (int v = 0; v < sz; v++) {
        if (L[v].empty())
            continue;
        int u = L[v][0];
        if (matched[u] == -1) {
            matched[u] = v;
            da[v] = true;
        }
    }
    for (int v = 0; v < sz; v++) {
        if (!da[v] && dfs(v))
            cnt++;
    }
    int ans = 0;
    for (int v = 0; v < sz; v++)
        ans += da[v];
    cout << sz + szR - ans;
}

signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    int t = 1;
//    cin >> t;
    while (t--)
        solve();
    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 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 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 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 0 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 0 ms 204 KB Output is correct
35 Correct 0 ms 204 KB Output is correct
36 Correct 0 ms 204 KB Output is correct
37 Correct 0 ms 204 KB Output is correct
38 Correct 0 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 0 ms 204 KB Output is correct
41 Correct 0 ms 204 KB Output is correct
42 Correct 0 ms 204 KB Output is correct
43 Correct 0 ms 204 KB Output is correct
44 Correct 0 ms 204 KB Output is correct
45 Correct 0 ms 204 KB Output is correct
46 Correct 0 ms 204 KB Output is correct
47 Correct 0 ms 204 KB Output is correct
48 Correct 0 ms 204 KB Output is correct
49 Correct 0 ms 204 KB Output is correct
50 Correct 0 ms 204 KB Output is correct
51 Correct 0 ms 204 KB Output is correct
52 Correct 0 ms 204 KB Output is correct
53 Correct 0 ms 204 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 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 0 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 0 ms 204 KB Output is correct
35 Correct 0 ms 204 KB Output is correct
36 Correct 0 ms 204 KB Output is correct
37 Correct 0 ms 204 KB Output is correct
38 Correct 0 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 0 ms 204 KB Output is correct
41 Correct 0 ms 204 KB Output is correct
42 Correct 0 ms 204 KB Output is correct
43 Correct 0 ms 204 KB Output is correct
44 Correct 0 ms 204 KB Output is correct
45 Correct 0 ms 204 KB Output is correct
46 Correct 0 ms 204 KB Output is correct
47 Correct 0 ms 204 KB Output is correct
48 Correct 0 ms 204 KB Output is correct
49 Correct 0 ms 204 KB Output is correct
50 Correct 0 ms 204 KB Output is correct
51 Correct 0 ms 204 KB Output is correct
52 Correct 0 ms 204 KB Output is correct
53 Correct 0 ms 204 KB Output is correct
54 Correct 0 ms 268 KB Output is correct
55 Correct 1 ms 460 KB Output is correct
56 Correct 1 ms 332 KB Output is correct
57 Correct 2 ms 460 KB Output is correct
58 Correct 43 ms 7752 KB Output is correct
59 Correct 323 ms 60740 KB Output is correct
60 Correct 318 ms 60848 KB Output is correct
61 Correct 322 ms 60724 KB Output is correct
62 Correct 0 ms 204 KB Output is correct
63 Correct 329 ms 59208 KB Output is correct
64 Correct 871 ms 235352 KB Output is correct
65 Correct 1012 ms 244096 KB Output is correct
66 Correct 1321 ms 243712 KB Output is correct
67 Correct 288 ms 138256 KB Output is correct
68 Correct 312 ms 137440 KB Output is correct
69 Correct 297 ms 129848 KB Output is correct
70 Correct 86 ms 28104 KB Output is correct
71 Correct 88 ms 28228 KB Output is correct
72 Correct 87 ms 28068 KB Output is correct
73 Correct 95 ms 28060 KB Output is correct
74 Correct 98 ms 28056 KB Output is correct
75 Correct 90 ms 28036 KB Output is correct
76 Correct 93 ms 27952 KB Output is correct
77 Correct 97 ms 27944 KB Output is correct
78 Correct 104 ms 28004 KB Output is correct
79 Correct 103 ms 28068 KB Output is correct
80 Correct 107 ms 28140 KB Output is correct
81 Correct 114 ms 27972 KB Output is correct
82 Correct 99 ms 28124 KB Output is correct
83 Correct 126 ms 27944 KB Output is correct
84 Correct 108 ms 28008 KB Output is correct
85 Correct 103 ms 28000 KB Output is correct
86 Correct 130 ms 27972 KB Output is correct
87 Correct 115 ms 27880 KB Output is correct
88 Correct 102 ms 27964 KB Output is correct
89 Correct 105 ms 27972 KB Output is correct
90 Correct 126 ms 27980 KB Output is correct