Submission #91341

# Submission time Handle Problem Language Result Execution time Memory
91341 2018-12-27T07:52:37 Z Just_Solve_The_Problem Marriage questions (IZhO14_marriage) C++11
70 / 100
1500 ms 5940 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 < gr[v].size(); i++) {
		int to = gr[v][i];
		if (mt[to] == -1 || kuhn(mt[to])) {
			mt[to] = v;
			prr[v] = to;
			return true;
		}
	}
	return false;
}

int check(int l) {
	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].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++;
	}
	int mx = 0;
	for (int i = 1; i <= m; i++) {
		if (prr[i] == -1) {
			return n + 1;
		}
		mx = max(mx, prr[i]);
	}
	return mx;
}

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].first = 0;
	}
	for (int i = 1; i <= n; i++) {
		int res = check(i);
		//cout << i << ' ' << res << endl;
		ans += (n - res + 1);
	}
	cout << ans << endl;
}

Compilation message

marriage.cpp: In function 'bool kuhn(int)':
marriage.cpp:19:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = lr[v].first; i < gr[v].size(); i++) {
                            ~~^~~~~~~~~~~~~~
marriage.cpp: At global scope:
marriage.cpp:58:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
marriage.cpp: In function 'int main()':
marriage.cpp:59: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:62:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &a, &b);
   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 504 KB Output isn't correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 712 KB Output is correct
4 Correct 2 ms 712 KB Output is correct
5 Correct 2 ms 712 KB Output is correct
6 Correct 2 ms 712 KB Output is correct
7 Incorrect 2 ms 712 KB Output isn't correct
8 Correct 4 ms 712 KB Output is correct
9 Correct 2 ms 712 KB Output is correct
10 Correct 2 ms 712 KB Output is correct
11 Correct 2 ms 712 KB Output is correct
12 Correct 2 ms 732 KB Output is correct
13 Correct 2 ms 792 KB Output is correct
14 Incorrect 2 ms 796 KB Output isn't correct
15 Incorrect 2 ms 800 KB Output isn't correct
16 Correct 2 ms 804 KB Output is correct
17 Correct 2 ms 828 KB Output is correct
18 Correct 2 ms 832 KB Output is correct
19 Incorrect 4 ms 912 KB Output isn't correct
20 Incorrect 3 ms 912 KB Output isn't correct
21 Correct 2 ms 912 KB Output is correct
22 Correct 3 ms 912 KB Output is correct
23 Correct 3 ms 992 KB Output is correct
24 Correct 3 ms 992 KB Output is correct
25 Incorrect 11 ms 1008 KB Output isn't correct
26 Incorrect 8 ms 1008 KB Output isn't correct
27 Correct 6 ms 1020 KB Output is correct
28 Correct 6 ms 1020 KB Output is correct
29 Correct 8 ms 1120 KB Output is correct
30 Correct 8 ms 1188 KB Output is correct
31 Incorrect 113 ms 1856 KB Output isn't correct
32 Incorrect 53 ms 1856 KB Output isn't correct
33 Correct 21 ms 1856 KB Output is correct
34 Correct 16 ms 1856 KB Output is correct
35 Correct 127 ms 2824 KB Output is correct
36 Correct 105 ms 3476 KB Output is correct
37 Incorrect 306 ms 3824 KB Output isn't correct
38 Correct 92 ms 4616 KB Output is correct
39 Correct 419 ms 4616 KB Output is correct
40 Correct 555 ms 4616 KB Output is correct
41 Incorrect 730 ms 4656 KB Output isn't correct
42 Correct 226 ms 4840 KB Output is correct
43 Correct 240 ms 5520 KB Output is correct
44 Correct 419 ms 5884 KB Output is correct
45 Incorrect 1375 ms 5884 KB Output isn't correct
46 Execution timed out 1565 ms 5884 KB Time limit exceeded
47 Correct 834 ms 5940 KB Output is correct
48 Correct 850 ms 5940 KB Output is correct
49 Execution timed out 1579 ms 5940 KB Time limit exceeded
50 Correct 1101 ms 5940 KB Output is correct