답안 #91337

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
91337 2018-12-27T07:41:47 Z Just_Solve_The_Problem 결혼 문제 (IZhO14_marriage) C++11
68 / 100
1500 ms 1404 KB
#include <bits/stdc++.h>

using namespace std;

#define ok puts("ok");
#define ll long long

const int N = (int)2e3 + 7;

int n, m, k;

vector < int > gr[N];
pair < int, int > lr[N];
int used[N], mt[(int)3e4 + 7], prr[N], cnt = 1;

bool kuhn(int v) {
	if (used[v] == cnt) return false;
	used[v] = cnt;
	for (int i = lr[v].first; i <= lr[v].second; i++) {
		int to = gr[v][i];
		if (mt[to] == -1 || kuhn(mt[to])) {
			mt[to] = v;
			prr[v] = to;
			return true;
		}
	}
	return false;
}

bool check(int l, int r) {
	for (int i = 1; i <= m; i++) {
		while (lr[i].first < (int)gr[i].size() && gr[i][lr[i].first] < l) lr[i].first++;
		while (lr[i].first > 0 && gr[i][lr[i].first - 1] >= l) lr[i].first--;
		while (lr[i].second + 1 < (int)gr[i].size() && gr[i][lr[i].second + 1] <= r) lr[i].second++;
		while (lr[i].second >= 0 && gr[i][lr[i].second] > r) lr[i].second--;
	}
	memset(mt, -1, sizeof mt);
	memset(prr, -1, sizeof prr);
	int run = 1;
	while (run) {
		run = 0;
		for (int i = 1; i <= m; i++) {
			if (prr[i] == -1 && kuhn(i)) {
				run = 1;
			}
		}
		cnt++;
	}
	for (int i = 1; i <= m; i++) {
		if (prr[i] == -1) {
			return 0;
		}
	}
	return 1;
}

main() {
	scanf("%d %d %d", &n, &m, &k);
	for (int i = 1; i <= k; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		gr[b].push_back(a);
	}
	ll ans = 0;
	for (int i = 1; i <= m; i++) {
		sort(gr[i].begin(), gr[i].end());
		lr[i].second = -1;
		lr[i].first = gr[i].size();
	}
	for (int i = 1; i <= n; i++) {
		int lo = i;
		int hi = n + 1;
		while (hi - lo > 1) {
			int mid = (lo + hi) >> 1;
			if (check(i, mid)) {
				hi = mid;
			} else {
				lo = mid;
			}
		}
		ans += (n - hi + 1);
	}
	cout << ans << endl;
}

Compilation message

marriage.cpp:57:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
marriage.cpp: In function 'int main()':
marriage.cpp:58:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d", &n, &m, &k);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
marriage.cpp:61:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &a, &b);
   ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 636 KB Output is correct
3 Correct 2 ms 636 KB Output is correct
4 Correct 2 ms 636 KB Output is correct
5 Correct 2 ms 636 KB Output is correct
6 Correct 2 ms 672 KB Output is correct
7 Correct 2 ms 672 KB Output is correct
8 Incorrect 2 ms 672 KB Output isn't correct
9 Correct 2 ms 688 KB Output is correct
10 Correct 2 ms 688 KB Output is correct
11 Correct 2 ms 736 KB Output is correct
12 Correct 2 ms 736 KB Output is correct
13 Incorrect 2 ms 748 KB Output isn't correct
14 Correct 2 ms 764 KB Output is correct
15 Correct 2 ms 764 KB Output is correct
16 Correct 2 ms 764 KB Output is correct
17 Correct 2 ms 764 KB Output is correct
18 Correct 2 ms 764 KB Output is correct
19 Correct 10 ms 804 KB Output is correct
20 Correct 8 ms 804 KB Output is correct
21 Correct 6 ms 804 KB Output is correct
22 Correct 6 ms 804 KB Output is correct
23 Correct 7 ms 804 KB Output is correct
24 Correct 7 ms 804 KB Output is correct
25 Correct 92 ms 888 KB Output is correct
26 Correct 61 ms 888 KB Output is correct
27 Correct 33 ms 888 KB Output is correct
28 Correct 30 ms 888 KB Output is correct
29 Correct 39 ms 888 KB Output is correct
30 Correct 36 ms 888 KB Output is correct
31 Execution timed out 1510 ms 1128 KB Time limit exceeded
32 Correct 485 ms 1128 KB Output is correct
33 Correct 153 ms 1128 KB Output is correct
34 Correct 127 ms 1128 KB Output is correct
35 Correct 1464 ms 1352 KB Output is correct
36 Correct 1192 ms 1352 KB Output is correct
37 Execution timed out 1568 ms 1352 KB Time limit exceeded
38 Correct 912 ms 1380 KB Output is correct
39 Execution timed out 1562 ms 1380 KB Time limit exceeded
40 Execution timed out 1547 ms 1380 KB Time limit exceeded
41 Execution timed out 1564 ms 1380 KB Time limit exceeded
42 Execution timed out 1574 ms 1380 KB Time limit exceeded
43 Execution timed out 1561 ms 1380 KB Time limit exceeded
44 Execution timed out 1566 ms 1380 KB Time limit exceeded
45 Execution timed out 1570 ms 1380 KB Time limit exceeded
46 Execution timed out 1555 ms 1380 KB Time limit exceeded
47 Execution timed out 1568 ms 1380 KB Time limit exceeded
48 Execution timed out 1573 ms 1380 KB Time limit exceeded
49 Execution timed out 1559 ms 1404 KB Time limit exceeded
50 Execution timed out 1567 ms 1404 KB Time limit exceeded