# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
393011 | 2021-04-22T14:18:42 Z | patrikpavic2 | 결혼 문제 (IZhO14_marriage) | C++17 | 1047 ms | 3892 KB |
#include <cstdio> #include <cstring> #include <vector> #define PB push_back using namespace std; typedef long long ll; const int N = (1 << 15); int par[N], n, m, bio[N], k, un[N], cookie = 1; vector < int > v[N]; int jos[N], sz; bool dodaj(int x){ if(bio[x] == cookie) return 0; bio[x] = cookie; for(int y : v[x]){ if(un[y] && (par[y] == -1 || dodaj(par[y]))){ par[x] = y; par[y] = x; return 1; } } return 0; } int main(){ scanf("%d%d%d", &n, &m, &k); for(int i = 0;i < k;i++){ int a, b; scanf("%d%d", &a, &b); a--; b--; v[a].PB(n + b), v[b + n].PB(a); } memset(par, -1, sizeof(par)); for(int i = 0;i < m;i++) un[i + n] = 1, jos[i] = i + n; sz = m; int r = 0; ll ans = 0; for(int l = 0;l < n;l++){ if(l){ un[l - 1] = 0; if(par[l - 1] != -1){ par[par[l - 1]] = -1; dodaj(par[l - 1]); cookie++; if(par[par[l - 1]] == -1) jos[sz++] = par[l - 1]; } } while(r < n && sz > 0){ un[r] = 1; cookie++; while(sz > 0 && dodaj(jos[sz - 1])) sz--, cookie++; r++; } ans += (n + 1 - r) * (sz == 0); } printf("%lld\n", ans); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 1100 KB | Output is correct |
2 | Correct | 1 ms | 1100 KB | Output is correct |
3 | Correct | 1 ms | 1100 KB | Output is correct |
4 | Correct | 1 ms | 1100 KB | Output is correct |
5 | Correct | 1 ms | 1100 KB | Output is correct |
6 | Correct | 1 ms | 1104 KB | Output is correct |
7 | Correct | 1 ms | 1100 KB | Output is correct |
8 | Correct | 1 ms | 1100 KB | Output is correct |
9 | Correct | 1 ms | 1100 KB | Output is correct |
10 | Correct | 1 ms | 1100 KB | Output is correct |
11 | Correct | 1 ms | 1100 KB | Output is correct |
12 | Correct | 1 ms | 1192 KB | Output is correct |
13 | Correct | 1 ms | 1100 KB | Output is correct |
14 | Correct | 1 ms | 1100 KB | Output is correct |
15 | Correct | 1 ms | 1100 KB | Output is correct |
16 | Correct | 1 ms | 1100 KB | Output is correct |
17 | Correct | 1 ms | 1100 KB | Output is correct |
18 | Correct | 1 ms | 1100 KB | Output is correct |
19 | Correct | 4 ms | 1228 KB | Output is correct |
20 | Correct | 2 ms | 1100 KB | Output is correct |
21 | Correct | 1 ms | 1100 KB | Output is correct |
22 | Correct | 1 ms | 1100 KB | Output is correct |
23 | Correct | 2 ms | 1100 KB | Output is correct |
24 | Correct | 1 ms | 1100 KB | Output is correct |
25 | Correct | 32 ms | 1460 KB | Output is correct |
26 | Correct | 5 ms | 1228 KB | Output is correct |
27 | Correct | 1 ms | 1100 KB | Output is correct |
28 | Correct | 1 ms | 1100 KB | Output is correct |
29 | Correct | 5 ms | 1356 KB | Output is correct |
30 | Correct | 4 ms | 1328 KB | Output is correct |
31 | Correct | 440 ms | 2164 KB | Output is correct |
32 | Correct | 11 ms | 1352 KB | Output is correct |
33 | Correct | 1 ms | 1228 KB | Output is correct |
34 | Correct | 3 ms | 1228 KB | Output is correct |
35 | Correct | 190 ms | 3044 KB | Output is correct |
36 | Correct | 148 ms | 2880 KB | Output is correct |
37 | Correct | 1047 ms | 2392 KB | Output is correct |
38 | Correct | 46 ms | 3268 KB | Output is correct |
39 | Correct | 73 ms | 1484 KB | Output is correct |
40 | Correct | 4 ms | 1612 KB | Output is correct |
41 | Correct | 10 ms | 1744 KB | Output is correct |
42 | Correct | 11 ms | 2100 KB | Output is correct |
43 | Correct | 18 ms | 2380 KB | Output is correct |
44 | Correct | 31 ms | 3148 KB | Output is correct |
45 | Correct | 13 ms | 2380 KB | Output is correct |
46 | Correct | 86 ms | 3748 KB | Output is correct |
47 | Correct | 37 ms | 3700 KB | Output is correct |
48 | Correct | 33 ms | 3604 KB | Output is correct |
49 | Correct | 145 ms | 3892 KB | Output is correct |
50 | Correct | 232 ms | 1644 KB | Output is correct |