# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
167982 | 2019-12-11T05:55:34 Z | Trickster | Marriage questions (IZhO14_marriage) | C++14 | 892 ms | 2780 KB |
//Suleyman Atayew #include <algorithm> #include <iostream> #include <string.h> #include <stdio.h> #include <vector> #include <queue> #include <cmath> #include <map> #include <set> #define N 30010 #define ff first #define ss second #define pb push_back #define ll long long #define inf 1000000007 #define pii pair <int, int> using namespace std; int now; int a, b; int l, r; int T[N]; int v[N]; int n, m, k; queue <int> Q; vector <int> E[N]; int dfs(int x) { if(v[x] == now) return 0; v[x] = now; for(auto i: E[x]) if(i >= l && i <= r) if(T[i] == 0 || dfs(T[i])) return T[i] = x, 1; return 0; } void tap() { while(Q.size()) { int a = Q.front(); Q.pop(), now++; if(!dfs(a)) { Q.push(a); break; } } } int main() { scanf("%d%d%d", &n, &m, &k); for(int i = 1; i <= k; i++) { scanf("%d%d", &a, &b); E[b].pb(a); } for(int i = 1; i <= m; i++) Q.push(i); int ans = 0; for(l = 1; l <= n; l++) { r = max(r, l); tap(); while(r < n && Q.size()) r++, tap(); if(Q.size()) break; ans += n-r+1; if(T[l]) Q.push(T[l]), T[l] = 0; } printf("%d", ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1016 KB | Output is correct |
2 | Correct | 2 ms | 1016 KB | Output is correct |
3 | Correct | 2 ms | 1016 KB | Output is correct |
4 | Correct | 2 ms | 1016 KB | Output is correct |
5 | Correct | 3 ms | 1016 KB | Output is correct |
6 | Correct | 3 ms | 1016 KB | Output is correct |
7 | Correct | 3 ms | 1016 KB | Output is correct |
8 | Correct | 2 ms | 1016 KB | Output is correct |
9 | Correct | 3 ms | 1016 KB | Output is correct |
10 | Correct | 3 ms | 1016 KB | Output is correct |
11 | Correct | 3 ms | 1016 KB | Output is correct |
12 | Correct | 3 ms | 1016 KB | Output is correct |
13 | Correct | 3 ms | 1016 KB | Output is correct |
14 | Correct | 3 ms | 1068 KB | Output is correct |
15 | Correct | 2 ms | 1016 KB | Output is correct |
16 | Correct | 2 ms | 1016 KB | Output is correct |
17 | Correct | 3 ms | 1016 KB | Output is correct |
18 | Correct | 2 ms | 1016 KB | Output is correct |
19 | Correct | 5 ms | 1016 KB | Output is correct |
20 | Correct | 3 ms | 1016 KB | Output is correct |
21 | Correct | 3 ms | 1016 KB | Output is correct |
22 | Correct | 3 ms | 1016 KB | Output is correct |
23 | Correct | 3 ms | 1016 KB | Output is correct |
24 | Correct | 3 ms | 1016 KB | Output is correct |
25 | Correct | 45 ms | 1244 KB | Output is correct |
26 | Correct | 7 ms | 1016 KB | Output is correct |
27 | Correct | 3 ms | 1016 KB | Output is correct |
28 | Correct | 3 ms | 1016 KB | Output is correct |
29 | Correct | 5 ms | 1144 KB | Output is correct |
30 | Correct | 5 ms | 1144 KB | Output is correct |
31 | Correct | 305 ms | 1784 KB | Output is correct |
32 | Correct | 13 ms | 1144 KB | Output is correct |
33 | Correct | 3 ms | 1016 KB | Output is correct |
34 | Correct | 6 ms | 1144 KB | Output is correct |
35 | Correct | 101 ms | 2296 KB | Output is correct |
36 | Correct | 75 ms | 2168 KB | Output is correct |
37 | Correct | 892 ms | 1972 KB | Output is correct |
38 | Correct | 23 ms | 2424 KB | Output is correct |
39 | Correct | 105 ms | 1272 KB | Output is correct |
40 | Correct | 6 ms | 1272 KB | Output is correct |
41 | Correct | 9 ms | 1400 KB | Output is correct |
42 | Correct | 10 ms | 1528 KB | Output is correct |
43 | Correct | 14 ms | 1784 KB | Output is correct |
44 | Correct | 23 ms | 2412 KB | Output is correct |
45 | Correct | 13 ms | 1656 KB | Output is correct |
46 | Correct | 57 ms | 2568 KB | Output is correct |
47 | Correct | 26 ms | 2684 KB | Output is correct |
48 | Correct | 24 ms | 2552 KB | Output is correct |
49 | Correct | 107 ms | 2780 KB | Output is correct |
50 | Correct | 278 ms | 1400 KB | Output is correct |