# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
95474 | 2019-02-01T13:31:59 Z | choikiwon | Marriage questions (IZhO14_marriage) | C++17 | 788 ms | 4728 KB |
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int MN = 100010; int N, M, K; vector<int> adj[MN]; int vis[MN], who[MN], timer; vector<int> rem; bool dfs(int u, int l, int r) { if(vis[u] == timer) return false; vis[u] = timer; for(int i = 0; i < adj[u].size(); i++) { int v = adj[u][i]; if(v < l || r < v) continue; if(who[v] == -1 || dfs(who[v], l, r)) { who[v] = u; return true; } } return false; } bool check(int l, int r) { while(rem.size()) { int t = rem.back(); rem.pop_back(); timer++; if(!dfs(t, l, r)) { rem.push_back(t); return false; } } return true; } 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--; adj[b].push_back(a); } memset(who, -1, sizeof(who)); for(int i = 0; i < M; i++) rem.push_back(i); ll ans = 0; int j = 0; for(int i = 0; i < N; i++) { while(j <= N && !check(i, j - 1)) j++; if(rem.size()) break; ans += N - j + 1; if(who[i] != -1) { rem.push_back(who[i]); } } printf("%lld", ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 3064 KB | Output is correct |
2 | Correct | 4 ms | 3064 KB | Output is correct |
3 | Correct | 4 ms | 3064 KB | Output is correct |
4 | Correct | 4 ms | 3064 KB | Output is correct |
5 | Correct | 3 ms | 3064 KB | Output is correct |
6 | Correct | 4 ms | 3064 KB | Output is correct |
7 | Correct | 4 ms | 3064 KB | Output is correct |
8 | Correct | 4 ms | 3064 KB | Output is correct |
9 | Correct | 4 ms | 3064 KB | Output is correct |
10 | Correct | 4 ms | 3064 KB | Output is correct |
11 | Correct | 4 ms | 3064 KB | Output is correct |
12 | Correct | 4 ms | 3064 KB | Output is correct |
13 | Correct | 6 ms | 3064 KB | Output is correct |
14 | Correct | 4 ms | 3064 KB | Output is correct |
15 | Correct | 4 ms | 3064 KB | Output is correct |
16 | Correct | 4 ms | 3064 KB | Output is correct |
17 | Correct | 4 ms | 3064 KB | Output is correct |
18 | Correct | 4 ms | 3064 KB | Output is correct |
19 | Correct | 6 ms | 3064 KB | Output is correct |
20 | Correct | 5 ms | 3064 KB | Output is correct |
21 | Correct | 4 ms | 3064 KB | Output is correct |
22 | Correct | 4 ms | 3064 KB | Output is correct |
23 | Correct | 5 ms | 3064 KB | Output is correct |
24 | Correct | 4 ms | 3036 KB | Output is correct |
25 | Correct | 39 ms | 3192 KB | Output is correct |
26 | Correct | 8 ms | 3064 KB | Output is correct |
27 | Correct | 4 ms | 3064 KB | Output is correct |
28 | Correct | 4 ms | 3064 KB | Output is correct |
29 | Correct | 6 ms | 3192 KB | Output is correct |
30 | Correct | 6 ms | 3192 KB | Output is correct |
31 | Correct | 279 ms | 3704 KB | Output is correct |
32 | Correct | 5 ms | 3192 KB | Output is correct |
33 | Correct | 4 ms | 3064 KB | Output is correct |
34 | Correct | 5 ms | 3064 KB | Output is correct |
35 | Correct | 106 ms | 4344 KB | Output is correct |
36 | Correct | 83 ms | 4216 KB | Output is correct |
37 | Correct | 788 ms | 3904 KB | Output is correct |
38 | Correct | 24 ms | 4344 KB | Output is correct |
39 | Correct | 65 ms | 3192 KB | Output is correct |
40 | Correct | 7 ms | 3192 KB | Output is correct |
41 | Correct | 11 ms | 3448 KB | Output is correct |
42 | Correct | 11 ms | 3448 KB | Output is correct |
43 | Correct | 14 ms | 3704 KB | Output is correct |
44 | Correct | 21 ms | 4472 KB | Output is correct |
45 | Correct | 12 ms | 3576 KB | Output is correct |
46 | Correct | 28 ms | 4600 KB | Output is correct |
47 | Correct | 25 ms | 4600 KB | Output is correct |
48 | Correct | 22 ms | 4472 KB | Output is correct |
49 | Correct | 35 ms | 4728 KB | Output is correct |
50 | Correct | 210 ms | 3284 KB | Output is correct |