Submission #522019

# Submission time Handle Problem Language Result Execution time Memory
522019 2022-02-03T15:35:38 Z Monarchuwu Dango Maker (JOI18_dango_maker) C++17
100 / 100
290 ms 182804 KB
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;

const int N = 3003, N2 = N * N, inf = 1e9 + 7;
int m, n;
char c[N][N];
vector<int> vertexX;

int cnt, num[2][2][N];
int g[N2][3], sz[N2];
void init_graph() {
    for (int i = 1, tmp; i <= m; ++i) {
        for (int j = 1; j <= n; ++j) if (c[i][j] == 'G') {

            // check ngang
            if (c[i][j - 1] == 'R' && c[i][j + 1] == 'W') {
                num[0][1][j] = ++cnt;
                vertexX.push_back(cnt);

                tmp = num[1][0][j + 1];
                if (tmp)
                    g[cnt][sz[cnt]++] = tmp;
            }

            // check dọc
            if (c[i - 1][j] == 'R' && c[i + 1][j] == 'W') {
                num[1][1][j] = ++cnt;

                tmp = num[0][0][j + 1];
                if (tmp)
                    g[tmp][sz[tmp]++] = cnt;
            }

            if (num[0][1][j] && num[1][1][j])
                g[cnt - 1][sz[cnt - 1]++] = cnt;
        }

        copy(num[0][1] + 1, num[0][1] + n + 1, num[0][0] + 1);
        fill(num[0][1] + 1, num[0][1] + n + 1, 0);

        copy(num[1][1] + 1, num[1][1] + n + 1, num[1][0] + 1);
        fill(num[1][1] + 1, num[1][1] + n + 1, 0);
    }
}

int mat[N2], dist[N2];
bool bfs() {
    queue<int> q;
    dist[0] = inf;
    for (int i : vertexX)
        if (mat[i]) dist[i] = inf;
        else {
            dist[i] = 0;
            q.push(i);
        }

    while (!q.empty()) {
        int u = q.front(); q.pop();
        for (int i = 0, v; i < sz[u]; ++i) {
            v = g[u][i];
            if (dist[mat[v]] == inf) {
                dist[mat[v]] = dist[u] + 1;
                q.push(mat[v]);
            }
        }
    }
    return dist[0] != inf;
}

bool dfs(int u) {
    for (int i = 0, v; i < sz[u]; ++i) {
        v = g[u][i];
        if (!mat[v] || (dist[mat[v]] == dist[u] + 1 && dfs(mat[v]))) {
            mat[v] = u, mat[u] = v;
            dist[u] = inf;
            return true;
        }
    }
    dist[u] = inf;
    return false;
}

int hopcroft_karp() {
    int ans(0);
    while (bfs()) {
        for (int i : vertexX)
            if (!mat[i] && dfs(i)) ++ans;
    }
    return ans;
}

int main() {
    cin.tie(NULL)->sync_with_stdio(false);
    cin >> m >> n;
    for (int i = 1; i <= m; ++i) cin >> (c[i] + 1);
    init_graph();

    cout << cnt - hopcroft_karp() << '\n';
}
/**  /\_/\
 *  (= ._.)
 *  / >0  \>1
**/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 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 0 ms 332 KB Output is correct
20 Correct 0 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 1 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 332 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 1 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 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 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 0 ms 332 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 0 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 1 ms 332 KB Output is correct
48 Correct 0 ms 332 KB Output is correct
49 Correct 1 ms 332 KB Output is correct
50 Correct 1 ms 332 KB Output is correct
51 Correct 0 ms 332 KB Output is correct
52 Correct 0 ms 332 KB Output is correct
53 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 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 0 ms 332 KB Output is correct
20 Correct 0 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 1 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 332 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 1 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 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 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 0 ms 332 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 0 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 1 ms 332 KB Output is correct
48 Correct 0 ms 332 KB Output is correct
49 Correct 1 ms 332 KB Output is correct
50 Correct 1 ms 332 KB Output is correct
51 Correct 0 ms 332 KB Output is correct
52 Correct 0 ms 332 KB Output is correct
53 Correct 0 ms 332 KB Output is correct
54 Correct 0 ms 332 KB Output is correct
55 Correct 4 ms 9036 KB Output is correct
56 Correct 1 ms 460 KB Output is correct
57 Correct 4 ms 6220 KB Output is correct
58 Correct 16 ms 5456 KB Output is correct
59 Correct 113 ms 27704 KB Output is correct
60 Correct 103 ms 36488 KB Output is correct
61 Correct 116 ms 36584 KB Output is correct
62 Correct 0 ms 332 KB Output is correct
63 Correct 103 ms 35540 KB Output is correct
64 Correct 220 ms 182804 KB Output is correct
65 Correct 269 ms 182768 KB Output is correct
66 Correct 290 ms 182396 KB Output is correct
67 Correct 36 ms 17952 KB Output is correct
68 Correct 34 ms 18596 KB Output is correct
69 Correct 52 ms 43092 KB Output is correct
70 Correct 27 ms 22588 KB Output is correct
71 Correct 29 ms 22500 KB Output is correct
72 Correct 28 ms 22560 KB Output is correct
73 Correct 28 ms 22504 KB Output is correct
74 Correct 29 ms 22520 KB Output is correct
75 Correct 30 ms 22584 KB Output is correct
76 Correct 29 ms 22504 KB Output is correct
77 Correct 29 ms 22492 KB Output is correct
78 Correct 30 ms 22456 KB Output is correct
79 Correct 31 ms 22492 KB Output is correct
80 Correct 33 ms 22496 KB Output is correct
81 Correct 31 ms 22484 KB Output is correct
82 Correct 31 ms 22548 KB Output is correct
83 Correct 33 ms 22472 KB Output is correct
84 Correct 38 ms 22460 KB Output is correct
85 Correct 34 ms 22464 KB Output is correct
86 Correct 31 ms 22492 KB Output is correct
87 Correct 31 ms 22476 KB Output is correct
88 Correct 32 ms 22484 KB Output is correct
89 Correct 32 ms 22472 KB Output is correct
90 Correct 32 ms 22460 KB Output is correct