Submission #363492

# Submission time Handle Problem Language Result Execution time Memory
363492 2021-02-06T09:14:55 Z nicolaalexandra Marriage questions (IZhO14_marriage) C++14
72 / 100
1500 ms 3052 KB
#include <bits/stdc++.h>
#define DIM 30010
using namespace std;

vector <int> L[DIM];
bitset <DIM> f;
int Left[DIM],Right[DIM];
int n,m,k,i,x,y,cnt;

int cupleaza (int nod, int x, int y){
    if (f[nod])
        return 0;
    f[nod] = 1;
    for (auto vecin : L[nod]){
        if (!(vecin >= x && vecin <= y))
            continue;

        if (!Right[vecin]){
            Right[vecin] = nod;
            Left[nod] = vecin;
            cnt++;
            return 1;
        }
    }

    for (auto vecin : L[nod]){
        if (!(vecin >= x && vecin <= y))
            continue;

        if (cupleaza (Right[vecin],x,y)){
            Left[nod] = vecin;
            Right[vecin] = nod;
            return 1;
        }
    }

    return 0;
}

int cuplaj (int x, int y){

    memset (Left,0,sizeof Left);
    memset (Right,0,sizeof Right);

    int ok = 0;
    cnt = 0;

    do{
        f.reset();
        ok = 0;
        for (int i=1;i<=n;i++){
            if (!Left[i] && cupleaza (i,x,y))
                ok = 1;
        }

    } while (ok);

    return cnt;
}

int main (){

    //ifstream cin ("date.in");
    //ofstream cout ("date.out");

    cin>>m>>n>>k;
    for (i=1;i<=k;i++){
        cin>>x>>y;
        L[y].push_back(x);
    }

    int sol = 0;
    for (i=n;i<=m;i++){
        int st = 1, dr = i, poz = 0;
        while (st <= dr){

            int mid = (st+dr)>>1;
            if (cuplaj(mid,i) == n){
                poz = mid;
                st = mid+1;
            } else dr = mid-1;

        }

        sol += poz;
    }

    cout<<sol;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1260 KB Output is correct
2 Correct 1 ms 1272 KB Output is correct
3 Correct 1 ms 1260 KB Output is correct
4 Correct 1 ms 1260 KB Output is correct
5 Correct 1 ms 1260 KB Output is correct
6 Correct 1 ms 1280 KB Output is correct
7 Correct 2 ms 1260 KB Output is correct
8 Correct 1 ms 1280 KB Output is correct
9 Correct 1 ms 1260 KB Output is correct
10 Correct 1 ms 1004 KB Output is correct
11 Correct 1 ms 1260 KB Output is correct
12 Correct 1 ms 1280 KB Output is correct
13 Correct 1 ms 1260 KB Output is correct
14 Correct 2 ms 1260 KB Output is correct
15 Correct 2 ms 1260 KB Output is correct
16 Correct 1 ms 1260 KB Output is correct
17 Correct 2 ms 1260 KB Output is correct
18 Correct 2 ms 1260 KB Output is correct
19 Correct 12 ms 1260 KB Output is correct
20 Correct 7 ms 1260 KB Output is correct
21 Correct 4 ms 1260 KB Output is correct
22 Correct 4 ms 1260 KB Output is correct
23 Correct 6 ms 1260 KB Output is correct
24 Correct 5 ms 1280 KB Output is correct
25 Correct 393 ms 1388 KB Output is correct
26 Correct 105 ms 1388 KB Output is correct
27 Correct 35 ms 1260 KB Output is correct
28 Correct 35 ms 1260 KB Output is correct
29 Correct 87 ms 1388 KB Output is correct
30 Correct 70 ms 1388 KB Output is correct
31 Execution timed out 1585 ms 1900 KB Time limit exceeded
32 Correct 296 ms 1516 KB Output is correct
33 Correct 100 ms 1388 KB Output is correct
34 Correct 94 ms 1260 KB Output is correct
35 Correct 1327 ms 2668 KB Output is correct
36 Correct 1071 ms 2540 KB Output is correct
37 Execution timed out 1579 ms 2028 KB Time limit exceeded
38 Correct 1405 ms 2668 KB Output is correct
39 Execution timed out 1590 ms 1644 KB Time limit exceeded
40 Execution timed out 1557 ms 1388 KB Time limit exceeded
41 Execution timed out 1592 ms 1644 KB Time limit exceeded
42 Execution timed out 1585 ms 1644 KB Time limit exceeded
43 Execution timed out 1555 ms 1900 KB Time limit exceeded
44 Execution timed out 1589 ms 2668 KB Time limit exceeded
45 Execution timed out 1543 ms 1772 KB Time limit exceeded
46 Execution timed out 1576 ms 2796 KB Time limit exceeded
47 Execution timed out 1589 ms 2924 KB Time limit exceeded
48 Execution timed out 1585 ms 2668 KB Time limit exceeded
49 Execution timed out 1582 ms 3052 KB Time limit exceeded
50 Execution timed out 1585 ms 1388 KB Time limit exceeded