답안 #207893

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
207893 2020-03-09T11:34:22 Z opukittpceno_hhr Dango Maker (JOI18_dango_maker) C++17
컴파일 오류
0 ms 0 KB
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

const int N = 3001;

int a[N][N];

int read() {
	char c;
	cin >> c;
	if (c == 'R') return 0;
	if (c == 'G') return 1;
	if (c == 'W') return 2;
	assert(false);
	return -1;
}

int n, m;

int ok(int i, int j, int dir) {
	if (dir == 0) {
		if (i == 0 || i + 1 == n) return 0;
		return a[i - 1][j] == 0 && a[i][j] == 1 && a[i + 1][j] == 2;
	} else {
		if (j == 0 || j + 1 == m) return 0;
		return a[i][j - 1] == 0 && a[i][j] == 1 && a[i][j + 1] == 2;
	}
}

vector<pair<int, int>> gt(int i, int j, int dir) {
	if (dir == 0) {
		return {{i - 1, j}, {i, j}, {i + 1, j}};
	} else {
		return {{i, j - 1}, {i, j}, {i, j + 1}};
	}
}

bool inter(vector<pair<int, int>> &x, vector<pair<int, int>> &y) {
	for (auto f : x) {
		for (auto s : y) {
			if (f == s) return 1;
		}
	}
	return 0;
}

vector<vector<int>> g;

int used[N * N];
int clr[N * N];
int mt[N * N];


void dfs(int v, int c, int p) {
	clr[v] = c;
	used[v] = 1;
	for (auto t : g[v]) {
		if (t == p) continue;
		assert(!used[t]);
		if (!used[t]) dfs(t, c ^ 1, cur);
	}
}


int sm(int v) {
	if (used[v]) return 0;
	used[v] = 1;
	for (auto t : g[v]) {
		if (mt[t] == -1 || sm(mt[t])) {
			mt[t] = v;
			return 1;
		}
	}
	return 0;
}

void dfs2(int v) {
	used[v] = 1;
	for (auto t : g[v]) {
		if (mt[t] == v) continue;
		used[t] = 1;
		if (mt[t] != -1 && !used[mt[t]]) dfs2(mt[t]);
	}
}

int solve_mathing() {
	int f = (int)g.size();
	for (int i = 0; i < f; i++) {
		if (!used[i]) dfs(i, 0, -1);
	}
	fill(mt, mt + f, -1);
	fill(used, used + f, 0);
	for (int i = 0; i < f; i++) {
		if (!clr[i]) {
			fill(used, used + f, 0);
			sm(i);
		}
	}
	fill(used, used + f, 0);
	vector<int> ns(f);
	for (int i = 0; i < f; i++) {
		if (mt[i] != -1) {
			ns[mt[i]] = 1;
		}
	}
	for (int i = 0; i < f; i++) {
		if (!clr[i] && !ns[i]) {
			dfs2(i);
		}
	}
	int ans = 0;
	for (int i = 0; i < f; i++) {
		ans += (used[i] && !clr[i]);
	}
	for (int i = 0; i < f; i++) {
		ans += (!used[i] && clr[i]);
	}
	return ans;
}

vector<int> cd[N][N];

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			a[i][j] = read();
		}
	}
	vector<int> tk;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (ok(i, j, 0)) {
				tk.push_back({i * m + j});
				cd[i][j].push_back((int)tk.size() - 1);
			}
			if (ok(i, j, 1)) {
				tk.push_back({i * m + j + n * m});
				cd[i][j].push_back((int)tk.size() - 1);

			}
		}
	}
	auto get  = [&](int x) {
		int v = tk[x];
		int tp = (v / (n * m));
		v %= n * m;
		int i = v / m;
		int j = v % m;
		return gt(i, j, tp);
	};
	g.resize(tk.size());
	for (int i = 0; i < (int)tk.size(); i++) {
		int v = (tk[i] % (n * m));
		int ri = v / m;
		int rj = v % m;
		for (int ti = ri - 2; ti <= ri + 2; ti++) {
			for (int tj = rj - 2; tj <= rj + 2; tj++) {
				if (ti < 0 || tj < 0 || ti >= n || tj >= m) continue;
				for (auto j : cd[ti][tj]) {
					if (i == j) continue;
					vector<pair<int, int>> f = get(i);
					vector<pair<int, int>> s = get(j);
					if (inter(f, s)) {
						g[i].push_back(j);
					}
				}
			}
		}
	}
	cout << solve_mathing() << endl;
}

Compilation message

dango_maker.cpp: In function 'void dfs(int, int, int)':
dango_maker.cpp:80:31: error: 'cur' was not declared in this scope
   if (!used[t]) dfs(t, c ^ 1, cur);
                               ^~~
dango_maker.cpp:80:31: note: suggested alternative: 'clr'
   if (!used[t]) dfs(t, c ^ 1, cur);
                               ^~~
                               clr