Submission #154488

# Submission time Handle Problem Language Result Execution time Memory
154488 2019-09-22T06:20:57 Z srvlt Marriage questions (IZhO14_marriage) C++14
48 / 100
1500 ms 7560 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 = 32007;
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 ok() {
    for (int i = 1; i <= m; i++) {
        if (f[i + n] == -1) {
            return false;
        }
    }
    return true;
}

void del(int x) {
    int tmp = mt[x];
    if (tmp != -1) {
        f[tmp] = -1;
        mt[x] = -1;
    }
    rem[x] = true;
    for (auto i : q[x]) {
        if (f[i] == -1) {
            timer++;
            dfs(i);
        }
    }
    q[x] = {};
}

void add(int x) {
    for (auto i : w[x]) {
        q[x].pb(i);
        q[i].pb(x);
    }
    for (auto i : q[x]) {
        if (f[i] == -1) {
            timer++;
            dfs(i);
        }
    }
}

void solve(int tc) {
    for (int i = 0; i < N; i++) {
        f[i] = mt[i] = -1;
    }
    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 (ok()) {
                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 Incorrect 4 ms 2040 KB Output isn't correct
2 Correct 4 ms 2168 KB Output is correct
3 Correct 4 ms 2168 KB Output is correct
4 Incorrect 4 ms 2040 KB Output isn't correct
5 Correct 4 ms 2168 KB Output is correct
6 Correct 4 ms 2040 KB Output is correct
7 Incorrect 4 ms 2040 KB Output isn't correct
8 Correct 4 ms 2040 KB Output is correct
9 Correct 4 ms 2040 KB Output is correct
10 Correct 4 ms 2040 KB Output is correct
11 Incorrect 4 ms 2168 KB Output isn't correct
12 Correct 4 ms 2040 KB Output is correct
13 Correct 4 ms 2144 KB Output is correct
14 Incorrect 4 ms 2040 KB Output isn't correct
15 Incorrect 4 ms 2040 KB Output isn't correct
16 Incorrect 4 ms 2168 KB Output isn't correct
17 Incorrect 4 ms 2040 KB Output isn't correct
18 Incorrect 4 ms 2040 KB Output isn't correct
19 Incorrect 13 ms 2168 KB Output isn't correct
20 Incorrect 5 ms 2168 KB Output isn't correct
21 Correct 4 ms 2040 KB Output is correct
22 Incorrect 4 ms 2040 KB Output isn't correct
23 Incorrect 4 ms 2168 KB Output isn't correct
24 Incorrect 4 ms 2168 KB Output isn't correct
25 Incorrect 74 ms 2656 KB Output isn't correct
26 Incorrect 8 ms 2424 KB Output isn't correct
27 Correct 4 ms 2168 KB Output is correct
28 Incorrect 11 ms 2168 KB Output isn't correct
29 Correct 8 ms 2424 KB Output is correct
30 Correct 7 ms 2424 KB Output is correct
31 Execution timed out 1526 ms 4108 KB Time limit exceeded
32 Incorrect 17 ms 2296 KB Output isn't correct
33 Correct 4 ms 2172 KB Output is correct
34 Incorrect 6 ms 2168 KB Output isn't correct
35 Incorrect 65 ms 4984 KB Output isn't correct
36 Incorrect 55 ms 4856 KB Output isn't correct
37 Execution timed out 1564 ms 4088 KB Time limit exceeded
38 Correct 48 ms 5496 KB Output is correct
39 Incorrect 32 ms 2552 KB Output isn't correct
40 Correct 0 ms 2780 KB Output is correct
41 Correct 36 ms 3192 KB Output is correct
42 Correct 21 ms 3556 KB Output is correct
43 Correct 27 ms 3960 KB Output is correct
44 Correct 45 ms 5380 KB Output is correct
45 Correct 118 ms 4476 KB Output is correct
46 Incorrect 326 ms 7220 KB Output isn't correct
47 Correct 62 ms 6008 KB Output is correct
48 Correct 60 ms 5880 KB Output is correct
49 Correct 471 ms 7560 KB Output is correct
50 Incorrect 45 ms 2552 KB Output isn't correct