Submission #990451

# Submission time Handle Problem Language Result Execution time Memory
990451 2024-05-30T12:41:42 Z DAleksa Marriage questions (IZhO14_marriage) C++17
52 / 100
1500 ms 4988 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long

const int N = 1e5 + 10;
int n, m, k;
vector<int> g[N];
int mt[N];
bool mark[N];

bool dfs(int u) {
    if(mark[u]) return false;
    mark[u] = true;
    for(int v : g[u]) {
        if(mt[v] == -1 || dfs(mt[v])) {
            mt[v] = u;
            return true;
        }
    }
    return false;
}

int max_matching(int l, int r) {
    for(int i = 1; i <= m; i++) mt[i] = -1;
    int ans = 0;
    for(int i = l; i <= r; i++) {
        for(int j = l; j <= r; j++) mark[j] = false;
        dfs(i);
    }
    for(int i = 1; i <= m; i++) if(mt[i] != -1) ans++;
    return ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m >> k;
    for(int i = 1; i <= k; i++) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
    }
    int ans = 0;
    for(int l = 1; l <= n; l++) for(int r = l + m - 1; r <= n; r++) if(max_matching(l, r) == m) ans++;
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3420 KB Output is correct
2 Correct 1 ms 3420 KB Output is correct
3 Correct 1 ms 3420 KB Output is correct
4 Correct 1 ms 3420 KB Output is correct
5 Correct 1 ms 3420 KB Output is correct
6 Correct 1 ms 3420 KB Output is correct
7 Correct 1 ms 3420 KB Output is correct
8 Correct 1 ms 3420 KB Output is correct
9 Correct 1 ms 3420 KB Output is correct
10 Correct 1 ms 3420 KB Output is correct
11 Correct 1 ms 3420 KB Output is correct
12 Correct 1 ms 3420 KB Output is correct
13 Correct 1 ms 3420 KB Output is correct
14 Correct 1 ms 3420 KB Output is correct
15 Correct 1 ms 3420 KB Output is correct
16 Correct 1 ms 3420 KB Output is correct
17 Correct 1 ms 3420 KB Output is correct
18 Correct 1 ms 3420 KB Output is correct
19 Correct 38 ms 3420 KB Output is correct
20 Correct 14 ms 3420 KB Output is correct
21 Correct 2 ms 3420 KB Output is correct
22 Correct 9 ms 3420 KB Output is correct
23 Correct 20 ms 3420 KB Output is correct
24 Correct 14 ms 3420 KB Output is correct
25 Execution timed out 1599 ms 3676 KB Time limit exceeded
26 Execution timed out 1535 ms 3416 KB Time limit exceeded
27 Correct 303 ms 3420 KB Output is correct
28 Execution timed out 1523 ms 3416 KB Time limit exceeded
29 Execution timed out 1535 ms 3416 KB Time limit exceeded
30 Execution timed out 1564 ms 3420 KB Time limit exceeded
31 Execution timed out 1570 ms 3932 KB Time limit exceeded
32 Execution timed out 1544 ms 3416 KB Time limit exceeded
33 Correct 1370 ms 3420 KB Output is correct
34 Execution timed out 1580 ms 3420 KB Time limit exceeded
35 Execution timed out 1558 ms 4444 KB Time limit exceeded
36 Execution timed out 1559 ms 4444 KB Time limit exceeded
37 Execution timed out 1542 ms 4184 KB Time limit exceeded
38 Execution timed out 1576 ms 4956 KB Time limit exceeded
39 Execution timed out 1522 ms 3416 KB Time limit exceeded
40 Execution timed out 1535 ms 3672 KB Time limit exceeded
41 Execution timed out 1560 ms 3676 KB Time limit exceeded
42 Execution timed out 1566 ms 3932 KB Time limit exceeded
43 Execution timed out 1539 ms 4156 KB Time limit exceeded
44 Execution timed out 1583 ms 4440 KB Time limit exceeded
45 Execution timed out 1555 ms 4144 KB Time limit exceeded
46 Execution timed out 1537 ms 4956 KB Time limit exceeded
47 Execution timed out 1534 ms 4944 KB Time limit exceeded
48 Execution timed out 1540 ms 4696 KB Time limit exceeded
49 Execution timed out 1552 ms 4988 KB Time limit exceeded
50 Execution timed out 1561 ms 3420 KB Time limit exceeded