Submission #91342

# Submission time Handle Problem Language Result Execution time Memory
91342 2018-12-27T07:55:16 Z Just_Solve_The_Problem Marriage questions (IZhO14_marriage) C++11
70 / 100
1500 ms 1900 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++;
	}
	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 - m + 1; 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:56:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
marriage.cpp: In function 'int main()':
marriage.cpp:57: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:60: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 640 KB Output is correct
3 Correct 2 ms 640 KB Output is correct
4 Correct 2 ms 640 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 2 ms 640 KB Output is correct
7 Incorrect 2 ms 640 KB Output isn't correct
8 Correct 2 ms 640 KB Output is correct
9 Correct 2 ms 692 KB Output is correct
10 Correct 2 ms 692 KB Output is correct
11 Correct 2 ms 812 KB Output is correct
12 Correct 2 ms 812 KB Output is correct
13 Correct 2 ms 812 KB Output is correct
14 Incorrect 2 ms 812 KB Output isn't correct
15 Incorrect 2 ms 812 KB Output isn't correct
16 Correct 2 ms 812 KB Output is correct
17 Correct 2 ms 812 KB Output is correct
18 Correct 2 ms 812 KB Output is correct
19 Incorrect 3 ms 812 KB Output isn't correct
20 Incorrect 3 ms 824 KB Output isn't correct
21 Correct 2 ms 828 KB Output is correct
22 Correct 3 ms 832 KB Output is correct
23 Correct 3 ms 836 KB Output is correct
24 Correct 2 ms 848 KB Output is correct
25 Incorrect 10 ms 980 KB Output isn't correct
26 Incorrect 6 ms 980 KB Output isn't correct
27 Correct 5 ms 980 KB Output is correct
28 Correct 5 ms 1000 KB Output is correct
29 Correct 7 ms 1000 KB Output is correct
30 Correct 6 ms 1000 KB Output is correct
31 Incorrect 46 ms 1244 KB Output isn't correct
32 Incorrect 16 ms 1244 KB Output isn't correct
33 Correct 10 ms 1244 KB Output is correct
34 Correct 10 ms 1244 KB Output is correct
35 Correct 125 ms 1556 KB Output is correct
36 Correct 99 ms 1556 KB Output is correct
37 Incorrect 133 ms 1556 KB Output isn't correct
38 Correct 82 ms 1556 KB Output is correct
39 Correct 333 ms 1556 KB Output is correct
40 Correct 450 ms 1556 KB Output is correct
41 Incorrect 506 ms 1556 KB Output isn't correct
42 Correct 211 ms 1556 KB Output is correct
43 Correct 225 ms 1556 KB Output is correct
44 Correct 441 ms 1840 KB Output is correct
45 Incorrect 1305 ms 1840 KB Output isn't correct
46 Execution timed out 1557 ms 1840 KB Time limit exceeded
47 Correct 856 ms 1900 KB Output is correct
48 Correct 849 ms 1900 KB Output is correct
49 Execution timed out 1566 ms 1900 KB Time limit exceeded
50 Correct 1055 ms 1900 KB Output is correct