Submission #91335

# Submission time Handle Problem Language Result Execution time Memory
91335 2018-12-27T07:40:14 Z Just_Solve_The_Problem Marriage questions (IZhO14_marriage) C++11
58 / 100
1500 ms 4116 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 = 0;
		lr[i].first = 0;
	}
	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);
   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is 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 784 KB Output is correct
6 Correct 2 ms 884 KB Output is correct
7 Correct 2 ms 884 KB Output is correct
8 Incorrect 2 ms 884 KB Output isn't correct
9 Correct 2 ms 884 KB Output is correct
10 Correct 2 ms 884 KB Output is correct
11 Correct 2 ms 884 KB Output is correct
12 Runtime error 2 ms 936 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Incorrect 2 ms 1040 KB Output isn't correct
14 Correct 2 ms 1044 KB Output is correct
15 Correct 2 ms 1048 KB Output is correct
16 Correct 2 ms 1052 KB Output is correct
17 Correct 2 ms 1056 KB Output is correct
18 Correct 2 ms 1060 KB Output is correct
19 Correct 10 ms 1064 KB Output is correct
20 Correct 7 ms 1080 KB Output is correct
21 Runtime error 2 ms 1080 KB Execution killed with signal 11 (could be triggered by violating memory limits)
22 Correct 5 ms 1152 KB Output is correct
23 Correct 7 ms 1156 KB Output is correct
24 Correct 8 ms 1164 KB Output is correct
25 Correct 97 ms 1300 KB Output is correct
26 Correct 65 ms 1336 KB Output is correct
27 Runtime error 3 ms 1336 KB Execution killed with signal 11 (could be triggered by violating memory limits)
28 Correct 30 ms 1348 KB Output is correct
29 Correct 39 ms 1480 KB Output is correct
30 Correct 36 ms 1548 KB Output is correct
31 Execution timed out 1558 ms 2244 KB Time limit exceeded
32 Correct 489 ms 2244 KB Output is correct
33 Runtime error 3 ms 2244 KB Execution killed with signal 11 (could be triggered by violating memory limits)
34 Correct 131 ms 2244 KB Output is correct
35 Execution timed out 1518 ms 3308 KB Time limit exceeded
36 Correct 1234 ms 4084 KB Output is correct
37 Execution timed out 1565 ms 4084 KB Time limit exceeded
38 Correct 905 ms 4084 KB Output is correct
39 Execution timed out 1561 ms 4084 KB Time limit exceeded
40 Runtime error 5 ms 4084 KB Execution killed with signal 11 (could be triggered by violating memory limits)
41 Execution timed out 1566 ms 4084 KB Time limit exceeded
42 Execution timed out 1579 ms 4084 KB Time limit exceeded
43 Execution timed out 1565 ms 4084 KB Time limit exceeded
44 Execution timed out 1569 ms 4084 KB Time limit exceeded
45 Execution timed out 1583 ms 4084 KB Time limit exceeded
46 Execution timed out 1571 ms 4084 KB Time limit exceeded
47 Execution timed out 1574 ms 4084 KB Time limit exceeded
48 Execution timed out 1586 ms 4084 KB Time limit exceeded
49 Execution timed out 1575 ms 4116 KB Time limit exceeded
50 Execution timed out 1565 ms 4116 KB Time limit exceeded