Submission #87266

# Submission time Handle Problem Language Result Execution time Memory
87266 2018-11-30T06:32:51 Z Yaroslaff Marriage questions (IZhO14_marriage) C++14
100 / 100
1127 ms 13828 KB
#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define ll long long
//#define int ll
#define x1 epgjoijhgoj
#define y1 epggoijhgoj
#define ld double
#define endl '\n'
#define TIME 1.0*clock()/CLOCKS_PER_SEC

using namespace std;

mt19937 gen(chrono::system_clock::now().time_since_epoch().count());

const int M = 1e9 + 7;
const int MOD = 998244353;
const int N = 1e5 + 10;

int n, m, k, x, y, l, r, u[N], cur, res, p[N];
vector<int> g[N], mt(N, -1), us;

bool par(int v) {
    for (int i = p[v]; i < g[v].size(); i++) {
        int to = g[v][i];
        if (to < l) p[v]++;
        if (to >= r) return 0;
        if (us[to] || to < l) continue;
        us[to] = 1;
        if (mt[to] == -1 || par(mt[to])) {
            mt[to] = v;
            return 1;
        }
    }
    return 0;
}

void kun() {
    us.assign(n + 2, 0);
    for (int i = 0; i < m; i++) {
        if (!u[i] && par(i)) {
            u[i] = 1;
            cur++;
            return;
        }
    }
}

void add() {
    ++r;
    kun();
}

void del() {
    if (mt[l] != -1) {
        u[mt[l]] = 0;
        --cur;
    }
    l++;
    if (cur < m) kun();
}

main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifdef LOCAL
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    cin >> n >> m >> k;
    for (int i = 0; i < k; i++) {
        cin >> x >> y;--x;--y;
        g[y].pb(x);
    }
    for (int i = 0; i < N; i++)
        sort(g[i].begin(), g[i].end());
    for (; 1;) {
        while (r < n && cur < m) add();
        if (cur != m) break;
        res += n - r + 1;
        del();
    }
    cout << res;
    return 0;
}

Compilation message

marriage.cpp: In function 'bool par(int)':
marriage.cpp:26:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = p[v]; i < g[v].size(); i++) {
                        ~~^~~~~~~~~~~~~
marriage.cpp: At global scope:
marriage.cpp:65:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3064 KB Output is correct
2 Correct 6 ms 3208 KB Output is correct
3 Correct 5 ms 3332 KB Output is correct
4 Correct 5 ms 3332 KB Output is correct
5 Correct 5 ms 3360 KB Output is correct
6 Correct 4 ms 3408 KB Output is correct
7 Correct 5 ms 3408 KB Output is correct
8 Correct 5 ms 3536 KB Output is correct
9 Correct 5 ms 3536 KB Output is correct
10 Correct 5 ms 3600 KB Output is correct
11 Correct 4 ms 3600 KB Output is correct
12 Correct 5 ms 3600 KB Output is correct
13 Correct 5 ms 3600 KB Output is correct
14 Correct 5 ms 3600 KB Output is correct
15 Correct 5 ms 3600 KB Output is correct
16 Correct 5 ms 3600 KB Output is correct
17 Correct 5 ms 3600 KB Output is correct
18 Correct 5 ms 3600 KB Output is correct
19 Correct 6 ms 3600 KB Output is correct
20 Correct 5 ms 3600 KB Output is correct
21 Correct 5 ms 3600 KB Output is correct
22 Correct 5 ms 3680 KB Output is correct
23 Correct 5 ms 3728 KB Output is correct
24 Correct 5 ms 3728 KB Output is correct
25 Correct 13 ms 3792 KB Output is correct
26 Correct 7 ms 3792 KB Output is correct
27 Correct 5 ms 3792 KB Output is correct
28 Correct 5 ms 3792 KB Output is correct
29 Correct 6 ms 3904 KB Output is correct
30 Correct 8 ms 3988 KB Output is correct
31 Correct 80 ms 4684 KB Output is correct
32 Correct 9 ms 4684 KB Output is correct
33 Correct 7 ms 4684 KB Output is correct
34 Correct 9 ms 4684 KB Output is correct
35 Correct 83 ms 5624 KB Output is correct
36 Correct 67 ms 6252 KB Output is correct
37 Correct 274 ms 6508 KB Output is correct
38 Correct 40 ms 7552 KB Output is correct
39 Correct 275 ms 7552 KB Output is correct
40 Correct 136 ms 7552 KB Output is correct
41 Correct 129 ms 7608 KB Output is correct
42 Correct 194 ms 7920 KB Output is correct
43 Correct 170 ms 8316 KB Output is correct
44 Correct 236 ms 9520 KB Output is correct
45 Correct 754 ms 9608 KB Output is correct
46 Correct 1055 ms 10968 KB Output is correct
47 Correct 720 ms 11944 KB Output is correct
48 Correct 775 ms 12800 KB Output is correct
49 Correct 1127 ms 13828 KB Output is correct
50 Correct 958 ms 13828 KB Output is correct