답안 #154481

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
154481 2019-09-22T04:52:57 Z srvlt 결혼 문제 (IZhO14_marriage) C++14
70 / 100
1500 ms 4344 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;
        }
    }
}

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();
    }
}

Compilation message

marriage.cpp: In function 'bool kuhn()':
marriage.cpp:79:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 2 ms 508 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 3 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 3 ms 504 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 3 ms 504 KB Output is correct
17 Correct 2 ms 504 KB Output is correct
18 Correct 2 ms 504 KB Output is correct
19 Correct 6 ms 504 KB Output is correct
20 Correct 4 ms 504 KB Output is correct
21 Correct 3 ms 504 KB Output is correct
22 Correct 3 ms 504 KB Output is correct
23 Correct 3 ms 504 KB Output is correct
24 Correct 3 ms 508 KB Output is correct
25 Correct 57 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 504 KB Output is correct
29 Correct 8 ms 780 KB Output is correct
30 Correct 8 ms 760 KB Output is correct
31 Execution timed out 1574 ms 1844 KB Time limit exceeded
32 Correct 339 ms 760 KB Output is correct
33 Correct 12 ms 508 KB Output is correct
34 Correct 23 ms 504 KB Output is correct
35 Correct 229 ms 3784 KB Output is correct
36 Correct 176 ms 3276 KB Output is correct
37 Runtime error 18 ms 2552 KB Execution killed with signal 11 (could be triggered by violating memory limits)
38 Runtime error 39 ms 4344 KB Execution killed with signal 11 (could be triggered by violating memory limits)
39 Runtime error 3 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
40 Runtime error 3 ms 764 KB Execution killed with signal 11 (could be triggered by violating memory limits)
41 Runtime error 3 ms 760 KB Execution killed with signal 11 (could be triggered by violating memory limits)
42 Runtime error 3 ms 760 KB Execution killed with signal 11 (could be triggered by violating memory limits)
43 Runtime error 3 ms 760 KB Execution killed with signal 11 (could be triggered by violating memory limits)
44 Runtime error 3 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
45 Runtime error 3 ms 760 KB Execution killed with signal 11 (could be triggered by violating memory limits)
46 Runtime error 7 ms 732 KB Execution killed with signal 11 (could be triggered by violating memory limits)
47 Runtime error 3 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
48 Runtime error 3 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)