답안 #713619

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
713619 2023-03-22T16:34:33 Z alex_2008 결혼 문제 (IZhO14_marriage) C++14
86 / 100
488 ms 4252 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;
const int N = 50050;
int n, m, k;
vector <int> g[N];
bool used[N];
int mt[N];
bool kuhn(int v, int L, int R) {
	if (used[v]) return false;
	used[v] = true;
	for (auto it : g[v]) {
		if (it >= L && it <= R) {
			if (mt[it] == -1 || kuhn(mt[it], L, R)) {
				mt[it] = v;
				return true;
			}
		}
	}
	return false;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m >> k;
	for (int i = 1; i <= k; i++) {
		int a, b;
		cin >> a >> b;
		a += m;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	int l = m, r = n, ind = -1;
	while (l <= r) {
		int mid = (l + r) / 2;
		for (int i = 1; i <= mid; i++) {
			mt[i + m] = -1;
		}
		int cnt = 0;
		for (int i = 1; i <= m; i++) {
			for (int j = 1; j <= m; j++) {
				used[j] = false;
			}
			if (kuhn(i, 1, mid + m)) ++cnt;
		}
		if (cnt == m) {
			ind = mid;
			r = mid - 1;
		}
		else l = mid + 1;
	}
	if (ind == -1) {
		cout << "0\n";
		return 0;
	}
	for (int i = 1; i <= n; i++) {
		mt[i + m] = -1;
	}
	for (int i = 1; i <= m; i++) {
		for (int j = 1; j <= m; j++) {
			used[j] = false;
		}
		kuhn(i, 1, ind + m);
	}
	int answ = n - ind + 1;
	for (int i = 1; i <= n; i++) {
		if (mt[i + m] == -1) {
			answ += n - ind + 1;
			continue;
		}
		int girl = mt[i + m];
		while (ind <= n) {
			for (int j = 1; j <= m; j++) {
				used[j] = false;
			}
			if (kuhn(girl, i + 1, ind + m)) break;
			ind++;
		}
		if (ind == n + 1) break;
		answ += n - ind + 1;
	}
	cout << answ << "\n";
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 1 ms 1492 KB Output is correct
3 Correct 1 ms 1492 KB Output is correct
4 Correct 1 ms 1492 KB Output is correct
5 Correct 1 ms 1492 KB Output is correct
6 Correct 1 ms 1492 KB Output is correct
7 Correct 1 ms 1492 KB Output is correct
8 Correct 1 ms 1508 KB Output is correct
9 Correct 2 ms 1492 KB Output is correct
10 Correct 2 ms 1492 KB Output is correct
11 Correct 1 ms 1492 KB Output is correct
12 Correct 2 ms 1620 KB Output is correct
13 Correct 2 ms 1492 KB Output is correct
14 Correct 2 ms 1492 KB Output is correct
15 Incorrect 1 ms 1496 KB Output isn't correct
16 Correct 1 ms 1492 KB Output is correct
17 Correct 2 ms 1492 KB Output is correct
18 Correct 1 ms 1492 KB Output is correct
19 Correct 3 ms 1492 KB Output is correct
20 Correct 2 ms 1492 KB Output is correct
21 Correct 2 ms 1492 KB Output is correct
22 Correct 2 ms 1500 KB Output is correct
23 Correct 2 ms 1492 KB Output is correct
24 Correct 1 ms 1492 KB Output is correct
25 Correct 27 ms 1748 KB Output is correct
26 Incorrect 7 ms 1516 KB Output isn't correct
27 Correct 1 ms 1492 KB Output is correct
28 Correct 2 ms 1504 KB Output is correct
29 Correct 2 ms 1644 KB Output is correct
30 Correct 2 ms 1620 KB Output is correct
31 Correct 141 ms 2480 KB Output is correct
32 Incorrect 3 ms 1620 KB Output isn't correct
33 Correct 2 ms 1492 KB Output is correct
34 Correct 19 ms 1492 KB Output is correct
35 Correct 95 ms 3356 KB Output is correct
36 Correct 59 ms 3148 KB Output is correct
37 Correct 488 ms 2668 KB Output is correct
38 Correct 21 ms 3564 KB Output is correct
39 Correct 294 ms 1844 KB Output is correct
40 Correct 6 ms 1876 KB Output is correct
41 Incorrect 8 ms 2132 KB Output isn't correct
42 Correct 9 ms 2516 KB Output is correct
43 Correct 13 ms 2692 KB Output is correct
44 Correct 30 ms 3424 KB Output is correct
45 Incorrect 14 ms 2728 KB Output isn't correct
46 Incorrect 34 ms 3956 KB Output isn't correct
47 Correct 24 ms 3916 KB Output is correct
48 Correct 22 ms 3920 KB Output is correct
49 Incorrect 37 ms 4252 KB Output isn't correct
50 Correct 433 ms 2052 KB Output is correct