Submission #363508

# Submission time Handle Problem Language Result Execution time Memory
363508 2021-02-06T10:06:11 Z nicolaalexandra Marriage questions (IZhO14_marriage) C++14
90 / 100
1500 ms 2144 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,st,dr;

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

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

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

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

    return 0;
}


void cuplaj (){

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

    } while (ok);

}



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;
    st = 1;
    for (dr=1;dr<=m;dr++){

        if (dr >= n)
            cuplaj();

        while (cnt == n && st < dr){

            if (Right[st]){
                cnt--; /// ramane nodul din stanga necuplat
                int nod = Right[st];
                Left[nod] = Right[st] = 0;
            }

            st++;

            cuplaj();
        }

        sol += st - 1;
    }

    cout<<sol;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1004 KB Output is correct
2 Correct 1 ms 1004 KB Output is correct
3 Correct 1 ms 1004 KB Output is correct
4 Correct 1 ms 1004 KB Output is correct
5 Correct 1 ms 1004 KB Output is correct
6 Correct 1 ms 1004 KB Output is correct
7 Correct 1 ms 1004 KB Output is correct
8 Incorrect 1 ms 1004 KB Output isn't correct
9 Correct 1 ms 1004 KB Output is correct
10 Correct 1 ms 1004 KB Output is correct
11 Correct 1 ms 1004 KB Output is correct
12 Correct 1 ms 1004 KB Output is correct
13 Incorrect 1 ms 1004 KB Output isn't correct
14 Correct 1 ms 1004 KB Output is correct
15 Correct 1 ms 1004 KB Output is correct
16 Correct 1 ms 1004 KB Output is correct
17 Correct 1 ms 1004 KB Output is correct
18 Correct 1 ms 1004 KB Output is correct
19 Correct 5 ms 1004 KB Output is correct
20 Correct 2 ms 1004 KB Output is correct
21 Correct 1 ms 1004 KB Output is correct
22 Correct 1 ms 1004 KB Output is correct
23 Correct 2 ms 1004 KB Output is correct
24 Correct 1 ms 1004 KB Output is correct
25 Correct 70 ms 1260 KB Output is correct
26 Correct 7 ms 1004 KB Output is correct
27 Correct 1 ms 1004 KB Output is correct
28 Correct 2 ms 1004 KB Output is correct
29 Correct 10 ms 1132 KB Output is correct
30 Correct 8 ms 1132 KB Output is correct
31 Correct 410 ms 1388 KB Output is correct
32 Correct 4 ms 1132 KB Output is correct
33 Correct 3 ms 1004 KB Output is correct
34 Correct 7 ms 1132 KB Output is correct
35 Correct 206 ms 1668 KB Output is correct
36 Correct 155 ms 1732 KB Output is correct
37 Correct 1260 ms 1644 KB Output is correct
38 Correct 91 ms 1644 KB Output is correct
39 Correct 233 ms 1260 KB Output is correct
40 Correct 111 ms 1260 KB Output is correct
41 Correct 82 ms 1260 KB Output is correct
42 Correct 654 ms 1388 KB Output is correct
43 Correct 1014 ms 1388 KB Output is correct
44 Execution timed out 1537 ms 2144 KB Time limit exceeded
45 Correct 333 ms 1388 KB Output is correct
46 Correct 239 ms 1900 KB Output is correct
47 Execution timed out 1569 ms 1772 KB Time limit exceeded
48 Execution timed out 1550 ms 1900 KB Time limit exceeded
49 Correct 251 ms 1772 KB Output is correct
50 Correct 625 ms 1388 KB Output is correct