Submission #522023

# Submission time Handle Problem Language Result Execution time Memory
522023 2022-02-03T15:38:33 Z Monarchuwu Dango Maker (JOI18_dango_maker) C++17
Compilation error
0 ms 0 KB
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;

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

int cnt, num[2][2][N];
vector<int> g[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];
int 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 v : g[u]) {
            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 v : g[u]) {
        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 = 0; i < m; ++i) cin >> (c[i] + 1);
    init_graph();

    cout << cnt - hopcroft_karp() << '\n';
}
/**  /\_/\
 *  (= ._.)
 *  / >0  \>1
**/

Compilation message

dango_maker.cpp: In function 'void init_graph()':
dango_maker.cpp:26:28: error: 'sz' was not declared in this scope
   26 |                     g[cnt][sz[cnt]++] = tmp;
      |                            ^~
dango_maker.cpp:35:28: error: 'sz' was not declared in this scope
   35 |                     g[tmp][sz[tmp]++] = cnt;
      |                            ^~
dango_maker.cpp:39:28: error: 'sz' was not declared in this scope
   39 |                 g[cnt - 1][sz[cnt - 1]++] = cnt;
      |                            ^~