# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
91415 | 2018-12-27T11:56:00 Z | mirbek01 | 결혼 문제 (IZhO14_marriage) | C++11 | 314 ms | 3232 KB |
# include <bits/stdc++.h> using namespace std; const int N = 30002; int n, m, k, mt[N], used[N], ans, L, R, pt = 1; vector <int> g[N], mr; bool dfs(int v){ if(used[v]) return 0; used[v] = 1; for(int to : g[v]){ if(to < L) break; if(to <= n && to > R) continue; if(mt[to] == -1 || dfs(mt[to])){ mt[to] = v; mt[v] = to; return true; } } return false; } bool check(){ while(!mr.empty()){ int v = mr.back(); if(mt[v] == -1){ memset(used, 0, sizeof(used)); if(!dfs(v)) return false; } mr.pop_back(); } return mr.empty(); } int main(){ scanf("%d %d %d", &n, &m, &k); for(int i = 1; i <= k; i ++){ int a, b; scanf("%d %d", &a, &b); g[a].push_back(b + n); g[b + n].push_back(a); } for(int i = n + 1; i <= n + m; i ++) sort(g[i].rbegin(), g[i].rend()); memset(mt, -1, sizeof(mt)); for(int i = n + 1; i <= n + m; i ++) mr.push_back(i); for(int i = 1; i <= n; i ++){ L = i, R = pt; while(pt <= n && !check()) pt ++, R = pt; ans += n - pt + 1; if(mt[L] != -1){ mt[mt[L]] = -1; mr.push_back(mt[L]); } } printf("%d", ans); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1272 KB | Output is correct |
2 | Correct | 2 ms | 1272 KB | Output is correct |
3 | Correct | 2 ms | 1304 KB | Output is correct |
4 | Correct | 2 ms | 1304 KB | Output is correct |
5 | Correct | 3 ms | 1400 KB | Output is correct |
6 | Correct | 2 ms | 1400 KB | Output is correct |
7 | Correct | 2 ms | 1400 KB | Output is correct |
8 | Correct | 2 ms | 1400 KB | Output is correct |
9 | Correct | 2 ms | 1440 KB | Output is correct |
10 | Correct | 2 ms | 1440 KB | Output is correct |
11 | Correct | 2 ms | 1516 KB | Output is correct |
12 | Correct | 3 ms | 1532 KB | Output is correct |
13 | Correct | 2 ms | 1532 KB | Output is correct |
14 | Correct | 3 ms | 1532 KB | Output is correct |
15 | Correct | 2 ms | 1532 KB | Output is correct |
16 | Correct | 2 ms | 1532 KB | Output is correct |
17 | Correct | 3 ms | 1532 KB | Output is correct |
18 | Correct | 3 ms | 1532 KB | Output is correct |
19 | Correct | 5 ms | 1532 KB | Output is correct |
20 | Correct | 4 ms | 1532 KB | Output is correct |
21 | Correct | 3 ms | 1532 KB | Output is correct |
22 | Correct | 3 ms | 1536 KB | Output is correct |
23 | Correct | 4 ms | 1536 KB | Output is correct |
24 | Correct | 3 ms | 1536 KB | Output is correct |
25 | Correct | 20 ms | 1660 KB | Output is correct |
26 | Correct | 9 ms | 1660 KB | Output is correct |
27 | Correct | 5 ms | 1660 KB | Output is correct |
28 | Correct | 5 ms | 1660 KB | Output is correct |
29 | Correct | 7 ms | 1660 KB | Output is correct |
30 | Correct | 7 ms | 1664 KB | Output is correct |
31 | Correct | 117 ms | 2148 KB | Output is correct |
32 | Correct | 13 ms | 2148 KB | Output is correct |
33 | Correct | 8 ms | 2148 KB | Output is correct |
34 | Correct | 12 ms | 2148 KB | Output is correct |
35 | Correct | 157 ms | 2556 KB | Output is correct |
36 | Correct | 128 ms | 2556 KB | Output is correct |
37 | Correct | 314 ms | 2556 KB | Output is correct |
38 | Correct | 80 ms | 2816 KB | Output is correct |
39 | Correct | 147 ms | 2816 KB | Output is correct |
40 | Correct | 59 ms | 2816 KB | Output is correct |
41 | Correct | 70 ms | 2816 KB | Output is correct |
42 | Correct | 93 ms | 2816 KB | Output is correct |
43 | Correct | 96 ms | 2816 KB | Output is correct |
44 | Correct | 112 ms | 2816 KB | Output is correct |
45 | Incorrect | 184 ms | 2816 KB | Output isn't correct |
46 | Incorrect | 199 ms | 3196 KB | Output isn't correct |
47 | Incorrect | 185 ms | 3196 KB | Output isn't correct |
48 | Incorrect | 193 ms | 3196 KB | Output isn't correct |
49 | Incorrect | 199 ms | 3232 KB | Output isn't correct |
50 | Incorrect | 165 ms | 3232 KB | Output isn't correct |