# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
91348 | 2018-12-27T08:23:12 Z | Just_Solve_The_Problem | 결혼 문제 (IZhO14_marriage) | C++11 | 1500 ms | 4644 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; int val; 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 (to > val) break; 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 l = i; int r = n + 1; while (r - l > 1) { int mid = (l + r) >> 1; val = mid; int res = check(i); if (res != n + 1) { r = res; } else { l = mid; } } //cout << i << ' ' << r << endl; ans += (n - r + 1); } cout << ans << endl; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | 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 | 640 KB | Output is correct |
6 | Correct | 2 ms | 640 KB | Output is correct |
7 | Correct | 2 ms | 772 KB | Output is correct |
8 | Incorrect | 2 ms | 772 KB | Output isn't correct |
9 | Correct | 2 ms | 772 KB | Output is correct |
10 | Correct | 2 ms | 772 KB | Output is correct |
11 | Correct | 2 ms | 772 KB | Output is correct |
12 | Correct | 2 ms | 772 KB | Output is correct |
13 | Incorrect | 2 ms | 772 KB | Output isn't correct |
14 | Correct | 2 ms | 772 KB | Output is correct |
15 | Correct | 2 ms | 772 KB | Output is correct |
16 | Correct | 2 ms | 772 KB | Output is correct |
17 | Correct | 2 ms | 772 KB | Output is correct |
18 | Correct | 2 ms | 772 KB | Output is correct |
19 | Correct | 6 ms | 772 KB | Output is correct |
20 | Correct | 6 ms | 780 KB | Output is correct |
21 | Correct | 4 ms | 800 KB | Output is correct |
22 | Correct | 4 ms | 804 KB | Output is correct |
23 | Correct | 5 ms | 808 KB | Output is correct |
24 | Correct | 5 ms | 816 KB | Output is correct |
25 | Correct | 79 ms | 1040 KB | Output is correct |
26 | Correct | 49 ms | 1040 KB | Output is correct |
27 | Correct | 27 ms | 1040 KB | Output is correct |
28 | Correct | 27 ms | 1040 KB | Output is correct |
29 | Correct | 30 ms | 1092 KB | Output is correct |
30 | Correct | 29 ms | 1144 KB | Output is correct |
31 | Correct | 1014 ms | 1856 KB | Output is correct |
32 | Correct | 218 ms | 1856 KB | Output is correct |
33 | Correct | 81 ms | 1856 KB | Output is correct |
34 | Correct | 85 ms | 1856 KB | Output is correct |
35 | Execution timed out | 1559 ms | 2924 KB | Time limit exceeded |
36 | Correct | 1221 ms | 2924 KB | Output is correct |
37 | Execution timed out | 1561 ms | 2924 KB | Time limit exceeded |
38 | Correct | 730 ms | 2924 KB | Output is correct |
39 | Execution timed out | 1560 ms | 2924 KB | Time limit exceeded |
40 | Execution timed out | 1553 ms | 2924 KB | Time limit exceeded |
41 | Execution timed out | 1572 ms | 2924 KB | Time limit exceeded |
42 | Execution timed out | 1579 ms | 2924 KB | Time limit exceeded |
43 | Execution timed out | 1583 ms | 2924 KB | Time limit exceeded |
44 | Execution timed out | 1582 ms | 3632 KB | Time limit exceeded |
45 | Execution timed out | 1576 ms | 3632 KB | Time limit exceeded |
46 | Execution timed out | 1580 ms | 4644 KB | Time limit exceeded |
47 | Execution timed out | 1567 ms | 4644 KB | Time limit exceeded |
48 | Execution timed out | 1580 ms | 4644 KB | Time limit exceeded |
49 | Execution timed out | 1575 ms | 4644 KB | Time limit exceeded |
50 | Execution timed out | 1571 ms | 4644 KB | Time limit exceeded |