# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
92775 | 2019-01-04T13:26:01 Z | SamAnd | 결혼 문제 (IZhO14_marriage) | C++17 | 1500 ms | 33784 KB |
#pragma comment(linker,"/STACK:200000000") #define _CRT_SECURE_NO_WARNINGS #define mp make_pair #include <iostream> #include <algorithm> #include <cstdio> #include <vector> #include <map> #include <set> #include <queue> #include <list> #include <stack> #include <string> #include <cstring> void fp(); void sp(); using namespace std; const int N = 2003; struct ban { int x, d; }; int n1, n2, m; int n; int ans; vector<int> a[N]; int b[N][N]; int p[N]; bool c[N]; bool dfs(int x, int pp) { c[x] = true; p[x] = pp; if (x == n) return true; for (int i = 0; i <= n; ++i) { if (!c[i] && b[x][i]) { if (dfs(i, x)) return true; } } return false; } bool stg(int l, int r) { for (int i = 0; i <= n; ++i) { for (int j = 0; j <= n; ++j) { b[i][j] = 0; } } for (int i = l; i <= r; ++i) { b[0][i] = 1; for (int j = 0; j<a[i].size(); ++j) { b[i][a[i][j]] = 1; } } for (int i = n1 + 1; i<n; ++i) { b[i][n] = 1; } for (int i = 0; i <= n; ++i) c[i] = false; while (dfs(0, -1)) { int minu = N; for (int x = n; x != 0; x = p[x]) { minu = min(minu, b[p[x]][x]); } for (int x = n; x != 0; x = p[x]) { b[p[x]][x] -= minu; b[x][p[x]] += minu; } for (int i = 0; i <= n; ++i) c[i] = false; } int res = 0; for (int i = 0; i <= n; ++i) { res += b[n][i]; } return res == (n2); } int main() { ios_base::sync_with_stdio(false); //fp(); cin >> n1 >> n2 >> m; n = n1 + n2 + 1; for (int i = 0; i<m; ++i) { int x, y; cin >> x >> y; a[x].push_back(y + n1); } if (n2 == 1) { for (int l = 1; l <= n1; ++l) { for (int r = l; r <= n1; ++r) { if ((r - l + 1)<n2) continue; if (stg(l, r)) { ++ans; } } } } else { for (int l = 1; l <= n1; ++l) { for (int r = l + 1; r <= n1; ++r) { if ((r - l + 1)<n2) continue; if (stg(l, r)) { ++ans; } } } } cout << ans << endl; sp(); return 0; } void fp() { #ifndef OLYMP freopen("marriage.in", "r", stdin); freopen("marriage.out", "w", stdout); #endif } void sp() { #ifdef OLYMP system("pause"); #endif }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 504 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 504 KB | Output is correct |
5 | Correct | 2 ms | 504 KB | Output is correct |
6 | Correct | 2 ms | 508 KB | Output is correct |
7 | Correct | 2 ms | 504 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 2 ms | 376 KB | Output is correct |
11 | Correct | 2 ms | 376 KB | Output is correct |
12 | Correct | 2 ms | 376 KB | Output is correct |
13 | Correct | 2 ms | 376 KB | Output is correct |
14 | Correct | 2 ms | 504 KB | Output is correct |
15 | Correct | 2 ms | 504 KB | Output is correct |
16 | Correct | 2 ms | 504 KB | Output is correct |
17 | Correct | 2 ms | 504 KB | Output is correct |
18 | Correct | 2 ms | 504 KB | Output is correct |
19 | Correct | 526 ms | 1180 KB | Output is correct |
20 | Correct | 329 ms | 1272 KB | Output is correct |
21 | Correct | 232 ms | 1176 KB | Output is correct |
22 | Correct | 406 ms | 1272 KB | Output is correct |
23 | Correct | 377 ms | 1272 KB | Output is correct |
24 | Correct | 328 ms | 1144 KB | Output is correct |
25 | Execution timed out | 1578 ms | 4344 KB | Time limit exceeded |
26 | Execution timed out | 1580 ms | 4216 KB | Time limit exceeded |
27 | Execution timed out | 1574 ms | 4216 KB | Time limit exceeded |
28 | Execution timed out | 1575 ms | 4216 KB | Time limit exceeded |
29 | Execution timed out | 1575 ms | 4344 KB | Time limit exceeded |
30 | Execution timed out | 1573 ms | 4344 KB | Time limit exceeded |
31 | Execution timed out | 1577 ms | 12792 KB | Time limit exceeded |
32 | Execution timed out | 1564 ms | 12408 KB | Time limit exceeded |
33 | Execution timed out | 1572 ms | 12152 KB | Time limit exceeded |
34 | Execution timed out | 1580 ms | 12152 KB | Time limit exceeded |
35 | Execution timed out | 1563 ms | 12920 KB | Time limit exceeded |
36 | Execution timed out | 1574 ms | 12920 KB | Time limit exceeded |
37 | Runtime error | 3 ms | 632 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
38 | Runtime error | 49 ms | 33784 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
39 | Runtime error | 3 ms | 632 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
40 | Runtime error | 3 ms | 632 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
41 | Runtime error | 3 ms | 632 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
42 | Runtime error | 4 ms | 892 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
43 | Runtime error | 4 ms | 888 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
44 | Runtime error | 6 ms | 1016 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
45 | Runtime error | 3 ms | 632 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
46 | Runtime error | 3 ms | 632 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
47 | Runtime error | 4 ms | 1016 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
48 | Runtime error | 4 ms | 760 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
49 | Runtime error | 2 ms | 632 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
50 | Runtime error | 2 ms | 632 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |