Submission #154482

# Submission time Handle Problem Language Result Execution time Memory
154482 2019-09-22T04:53:32 Z srvlt Marriage questions (IZhO14_marriage) C++14
70 / 100
1500 ms 4220 KB
//#pragma GCC optimize("Ofast")
#pragma GCC target("sse2,avx")
#include <bits/stdc++.h>
#define ll long long
#define db long double
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define fi first
#define se second
#define mp make_pair
#define endl "\n"
//#define int long long
using namespace std;

void dout() {
    cerr << endl;
}

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 2007;
int n, m, k, mt[N], used[N], f[N], timer;
vector <int> q[N], w[N];
bool rem[N];

bool dfs(int v) {
    if (used[v] == timer) {
        return false;
    }
    used[v] = timer;
    for (auto i : q[v]) {
        if (rem[i]) {
            continue;
        }
        if (mt[i] == -1) {
            mt[i] = v;
            f[v] = i;
            return true;
        }
    }
    for (auto i : q[v]) {
        if (rem[i]) {
            continue;
        }
        if (dfs(mt[i])) {
            mt[i] = v;
            f[v] = i;
            return true;
        }
    }
    return false;
}

bool kuhn() {
    for (int i = 0; i < N; i++) {
        timer = 0;
        used[i] = 0;
        mt[i] = f[i] = -1;
    }
    for (int i = 1; i <= m; i++) {
        timer++;
        if (f[i + n] == -1) {
            dfs(i + n);
        }
    }
    for (int i = 1; i <= m; i++) {
        if (f[i + n] == -1) {
            return false;
        }
    }
    return true;
}

void del(int x) {
    rem[x] = true;
    q[x] = {};
}

void add(int x) {
    for (auto i : w[x]) {
        q[x].pb(i);
        q[i].pb(x);
    }
}

void solve(int tc) {
    cin >> n >> m >> k;
    for (int i = 1; i <= k; i++) {
        int x, y;
        cin >> x >> y;
        w[x].pb(y + n);
        w[y + n].pb(x);
    }
    int j = 1, res = 0;
    for (int i = 1; i <= n; i++) {
        while (j <= n) {
            add(j);
            if (kuhn()) {
                break;
            }
            j++;
        }
        res += (n - j + 1);
        del(i);
    }
    cout << res;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    int tc = 1;
//    cin >> tc;
    for (int i = 0; i < tc; i++) {
        solve(i);
//        cleanup();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 3 ms 536 KB Output is correct
10 Correct 2 ms 508 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 2 ms 380 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 504 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 7 ms 632 KB Output is correct
20 Correct 4 ms 504 KB Output is correct
21 Correct 3 ms 508 KB Output is correct
22 Correct 13 ms 508 KB Output is correct
23 Correct 4 ms 504 KB Output is correct
24 Correct 3 ms 504 KB Output is correct
25 Correct 56 ms 888 KB Output is correct
26 Correct 20 ms 504 KB Output is correct
27 Correct 5 ms 504 KB Output is correct
28 Correct 7 ms 508 KB Output is correct
29 Correct 9 ms 760 KB Output is correct
30 Correct 8 ms 764 KB Output is correct
31 Execution timed out 1528 ms 1656 KB Time limit exceeded
32 Correct 341 ms 632 KB Output is correct
33 Correct 13 ms 632 KB Output is correct
34 Correct 23 ms 632 KB Output is correct
35 Correct 228 ms 3764 KB Output is correct
36 Correct 177 ms 3320 KB Output is correct
37 Runtime error 19 ms 2552 KB Execution killed with signal 11 (could be triggered by violating memory limits)
38 Runtime error 40 ms 4220 KB Execution killed with signal 11 (could be triggered by violating memory limits)
39 Runtime error 4 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
40 Runtime error 3 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
41 Runtime error 3 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
42 Runtime error 3 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
43 Runtime error 3 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
44 Runtime error 3 ms 760 KB Execution killed with signal 11 (could be triggered by violating memory limits)
45 Runtime error 3 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
46 Runtime error 3 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
47 Runtime error 3 ms 764 KB Execution killed with signal 11 (could be triggered by violating memory limits)
48 Runtime error 10 ms 760 KB Execution killed with signal 11 (could be triggered by violating memory limits)
49 Runtime error 3 ms 760 KB Execution killed with signal 11 (could be triggered by violating memory limits)
50 Runtime error 3 ms 760 KB Execution killed with signal 11 (could be triggered by violating memory limits)