# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
91401 | 2018-12-27T11:11:22 Z | mirbek01 | 결혼 문제 (IZhO14_marriage) | C++11 | 1500 ms | 28584 KB |
# include <bits/stdc++.h> using namespace std; const int N = 1e5 + 2; int n, m, k, mt[N], used[N], ans, L, R; vector <int> g[N], vr, mat; set <int> mr; bool dfs(int v){ if(used[v]) return 0; vr.push_back(v); used[v] = 1; for(int to : g[v]){ if(to <= n && (to > R || to < L)) continue; if(mt[to] == -1 || dfs(mt[to])){ mt[to] = v; mt[v] = to; mat.push_back(to); mat.push_back(v); return true; } } return false; } bool check(){ if(mr.empty()) return true; while(!mr.empty()){ int v = *mr.begin(); for(int i = 0; i < vr.size(); i ++){ used[vr[i]] = 0; } if(!dfs(v)){ return false; } mr.erase(v); } return mr.empty(); } bool ok(){ for(int i = 0; i < mat.size(); i ++){ mt[mat[i]] = -1; } mat.clear(); for(int i = n + 1; i <= n + m; i ++){ for(int j = 0; j < (int)vr.size(); j ++){ used[ vr[j] ] = 0; } vr.clear(); dfs(i); } 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 = 1; i <= n + m; i ++){ sort(g[i].begin(), g[i].end()); } memset(mt, -1, sizeof(mt)); for(int i = n + 1; i <= n + m; i ++) mr.insert(i); int pt = 1; 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.insert(mt[L]); } } printf("%d", ans); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 3064 KB | Output is correct |
2 | Correct | 3 ms | 3068 KB | Output is correct |
3 | Correct | 3 ms | 3128 KB | Output is correct |
4 | Correct | 3 ms | 3176 KB | Output is correct |
5 | Correct | 3 ms | 3176 KB | Output is correct |
6 | Correct | 3 ms | 3176 KB | Output is correct |
7 | Correct | 4 ms | 3176 KB | Output is correct |
8 | Correct | 3 ms | 3176 KB | Output is correct |
9 | Correct | 3 ms | 3196 KB | Output is correct |
10 | Correct | 3 ms | 3244 KB | Output is correct |
11 | Correct | 3 ms | 3244 KB | Output is correct |
12 | Correct | 3 ms | 3244 KB | Output is correct |
13 | Correct | 3 ms | 3244 KB | Output is correct |
14 | Correct | 3 ms | 3244 KB | Output is correct |
15 | Correct | 3 ms | 3244 KB | Output is correct |
16 | Correct | 4 ms | 3244 KB | Output is correct |
17 | Correct | 5 ms | 3252 KB | Output is correct |
18 | Correct | 4 ms | 3252 KB | Output is correct |
19 | Correct | 5 ms | 3380 KB | Output is correct |
20 | Correct | 5 ms | 3396 KB | Output is correct |
21 | Correct | 4 ms | 3396 KB | Output is correct |
22 | Correct | 4 ms | 3396 KB | Output is correct |
23 | Correct | 4 ms | 3396 KB | Output is correct |
24 | Correct | 4 ms | 3396 KB | Output is correct |
25 | Correct | 48 ms | 4544 KB | Output is correct |
26 | Correct | 16 ms | 4544 KB | Output is correct |
27 | Correct | 4 ms | 4544 KB | Output is correct |
28 | Correct | 7 ms | 4544 KB | Output is correct |
29 | Correct | 6 ms | 4544 KB | Output is correct |
30 | Correct | 7 ms | 4544 KB | Output is correct |
31 | Correct | 544 ms | 10348 KB | Output is correct |
32 | Correct | 15 ms | 10348 KB | Output is correct |
33 | Correct | 4 ms | 10348 KB | Output is correct |
34 | Correct | 96 ms | 10348 KB | Output is correct |
35 | Correct | 195 ms | 10348 KB | Output is correct |
36 | Correct | 154 ms | 10348 KB | Output is correct |
37 | Execution timed out | 1549 ms | 19140 KB | Time limit exceeded |
38 | Correct | 33 ms | 19140 KB | Output is correct |
39 | Execution timed out | 1566 ms | 28508 KB | Time limit exceeded |
40 | Correct | 38 ms | 28508 KB | Output is correct |
41 | Correct | 226 ms | 28508 KB | Output is correct |
42 | Correct | 80 ms | 28508 KB | Output is correct |
43 | Correct | 84 ms | 28508 KB | Output is correct |
44 | Correct | 100 ms | 28508 KB | Output is correct |
45 | Correct | 565 ms | 28508 KB | Output is correct |
46 | Execution timed out | 1550 ms | 28508 KB | Time limit exceeded |
47 | Correct | 293 ms | 28508 KB | Output is correct |
48 | Correct | 297 ms | 28508 KB | Output is correct |
49 | Execution timed out | 1572 ms | 28508 KB | Time limit exceeded |
50 | Execution timed out | 1544 ms | 28584 KB | Time limit exceeded |