# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
96059 | 2019-02-05T13:56:25 Z | Kastanda | 결혼 문제 (IZhO14_marriage) | C++11 | 380 ms | 1928 KB |
#include<bits/stdc++.h> #define pb push_back using namespace std; const int MAXN = 34004; int n, m, k, ts, l, r, MC[MAXN], M[MAXN]; vector < int > Adj[MAXN]; queue < int > qu; bool DFS(int v) { if (M[v] == ts) return 0; M[v] = ts; for (int i = 0; i < (int)Adj[v].size() && Adj[v][i] <= r; i++) if (l <= Adj[v][i] && Adj[v][i] <= r) if (MC[Adj[v][i]] == -1 || DFS(MC[Adj[v][i]])) return MC[Adj[v][i]] = v, 1; return 0; } inline void Match() { while (qu.size()) { int v = qu.front(); qu.pop(); ts ++; if (!DFS(v)) { qu.push(v); return ; } } } int main() { scanf("%d%d%d", &n, &m, &k); for (int i = 1; i <= k; i++) { int v, u; scanf("%d%d", &v, &u); Adj[u].pb(v); } int tot = 0; memset(MC, -1, sizeof(MC)); for (int i = 1; i <= m; i++) qu.push(i), sort(Adj[i].begin(), Adj[i].end()); for (l = 1; l <= n; l ++) { r = max(r, l); Match(); while (r < n && qu.size()) r ++, Match(); if (qu.size()) break; tot += n - r + 1; if (MC[l] != -1) qu.push(MC[l]), MC[l] = -1; } return !printf("%d\n", tot); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1272 KB | Output is correct |
2 | Correct | 3 ms | 1272 KB | Output is correct |
3 | Correct | 3 ms | 1276 KB | Output is correct |
4 | Correct | 3 ms | 1272 KB | Output is correct |
5 | Correct | 2 ms | 1272 KB | Output is correct |
6 | Correct | 3 ms | 1272 KB | Output is correct |
7 | Correct | 3 ms | 1272 KB | Output is correct |
8 | Correct | 3 ms | 1272 KB | Output is correct |
9 | Correct | 2 ms | 1272 KB | Output is correct |
10 | Correct | 3 ms | 1272 KB | Output is correct |
11 | Correct | 2 ms | 1272 KB | Output is correct |
12 | Correct | 2 ms | 1272 KB | Output is correct |
13 | Correct | 3 ms | 1272 KB | Output is correct |
14 | Correct | 3 ms | 1272 KB | Output is correct |
15 | Correct | 2 ms | 1272 KB | Output is correct |
16 | Correct | 3 ms | 1272 KB | Output is correct |
17 | Correct | 3 ms | 1272 KB | Output is correct |
18 | Correct | 2 ms | 1272 KB | Output is correct |
19 | Correct | 4 ms | 1272 KB | Output is correct |
20 | Correct | 3 ms | 1272 KB | Output is correct |
21 | Correct | 3 ms | 1272 KB | Output is correct |
22 | Correct | 3 ms | 1272 KB | Output is correct |
23 | Correct | 3 ms | 1272 KB | Output is correct |
24 | Correct | 3 ms | 1272 KB | Output is correct |
25 | Correct | 19 ms | 1408 KB | Output is correct |
26 | Correct | 5 ms | 1272 KB | Output is correct |
27 | Correct | 3 ms | 1244 KB | Output is correct |
28 | Correct | 3 ms | 1272 KB | Output is correct |
29 | Correct | 4 ms | 1272 KB | Output is correct |
30 | Correct | 4 ms | 1272 KB | Output is correct |
31 | Correct | 129 ms | 1528 KB | Output is correct |
32 | Correct | 9 ms | 1272 KB | Output is correct |
33 | Correct | 3 ms | 1272 KB | Output is correct |
34 | Correct | 5 ms | 1276 KB | Output is correct |
35 | Correct | 108 ms | 1828 KB | Output is correct |
36 | Correct | 79 ms | 1784 KB | Output is correct |
37 | Correct | 380 ms | 1656 KB | Output is correct |
38 | Correct | 21 ms | 1784 KB | Output is correct |
39 | Correct | 72 ms | 1528 KB | Output is correct |
40 | Correct | 6 ms | 1400 KB | Output is correct |
41 | Correct | 10 ms | 1400 KB | Output is correct |
42 | Correct | 8 ms | 1400 KB | Output is correct |
43 | Correct | 12 ms | 1528 KB | Output is correct |
44 | Correct | 19 ms | 1784 KB | Output is correct |
45 | Correct | 12 ms | 1528 KB | Output is correct |
46 | Correct | 201 ms | 1912 KB | Output is correct |
47 | Correct | 21 ms | 1784 KB | Output is correct |
48 | Correct | 20 ms | 1784 KB | Output is correct |
49 | Correct | 287 ms | 1928 KB | Output is correct |
50 | Correct | 250 ms | 1400 KB | Output is correct |