# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
95471 | 2019-02-01T13:16:33 Z | choikiwon | Marriage questions (IZhO14_marriage) | C++17 | 203 ms | 4600 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; } 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 && rem.size()) { while(rem.size()) { int t = rem.back(); rem.pop_back(); timer++; if(!dfs(t, i, j)) { rem.push_back(t); break; } } 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 | Incorrect | 4 ms | 3064 KB | Output isn't correct |
2 | Incorrect | 4 ms | 3064 KB | Output isn't correct |
3 | Correct | 4 ms | 2936 KB | Output is correct |
4 | Correct | 4 ms | 3064 KB | Output is correct |
5 | Correct | 2 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 | 3 ms | 3064 KB | Output is correct |
9 | Correct | 3 ms | 3064 KB | Output is correct |
10 | Correct | 4 ms | 3064 KB | Output is correct |
11 | Correct | 3 ms | 3064 KB | Output is correct |
12 | Correct | 3 ms | 3064 KB | Output is correct |
13 | Correct | 3 ms | 3064 KB | Output is correct |
14 | Correct | 3 ms | 3064 KB | Output is correct |
15 | Correct | 4 ms | 2980 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 | 3068 KB | Output is correct |
19 | Correct | 4 ms | 3144 KB | Output is correct |
20 | Correct | 4 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 | 3064 KB | Output is correct |
25 | Correct | 10 ms | 3192 KB | Output is correct |
26 | Incorrect | 5 ms | 3064 KB | Output isn't correct |
27 | Correct | 4 ms | 3064 KB | Output is correct |
28 | Correct | 4 ms | 3064 KB | Output is correct |
29 | Incorrect | 6 ms | 3192 KB | Output isn't correct |
30 | Incorrect | 5 ms | 3192 KB | Output isn't correct |
31 | Correct | 89 ms | 3816 KB | Output is correct |
32 | Incorrect | 5 ms | 3064 KB | Output isn't correct |
33 | Correct | 4 ms | 3064 KB | Output is correct |
34 | Correct | 5 ms | 3064 KB | Output is correct |
35 | Correct | 48 ms | 4344 KB | Output is correct |
36 | Correct | 37 ms | 4216 KB | Output is correct |
37 | Correct | 186 ms | 3836 KB | Output is correct |
38 | Incorrect | 23 ms | 4344 KB | Output isn't correct |
39 | Correct | 75 ms | 3280 KB | Output is correct |
40 | Correct | 7 ms | 3312 KB | Output is correct |
41 | Incorrect | 9 ms | 3448 KB | Output isn't correct |
42 | Incorrect | 10 ms | 3448 KB | Output isn't correct |
43 | Incorrect | 15 ms | 3832 KB | Output isn't correct |
44 | Incorrect | 22 ms | 4472 KB | Output isn't correct |
45 | Incorrect | 12 ms | 3576 KB | Output isn't correct |
46 | Incorrect | 29 ms | 4600 KB | Output isn't correct |
47 | Incorrect | 25 ms | 4600 KB | Output isn't correct |
48 | Incorrect | 23 ms | 4472 KB | Output isn't correct |
49 | Incorrect | 32 ms | 4600 KB | Output isn't correct |
50 | Correct | 203 ms | 3192 KB | Output is correct |