Submission #364431

# Submission time Handle Problem Language Result Execution time Memory
364431 2021-02-09T06:10:40 Z nicolaalexandra Marriage questions (IZhO14_marriage) C++14
92 / 100
1500 ms 2876 KB
#include <bits/stdc++.h>
#define DIM 30010
#define DIMBUFF 7000000
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,pos;
char buff[DIMBUFF];

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 && cnt < n);

}


int get_nr (){

    while (!(buff[pos] >= '0' && buff[pos] <= '9'))
        pos++;

    int nr = 0;
    while (buff[pos] >= '0' && buff[pos] <= '9'){
        nr = nr * 10 + buff[pos] - '0';
        pos++;
    }

    return nr;

}

int main (){

    FILE *fin = stdin;
    FILE *fout = stdout;

    fread (buff,1,DIMBUFF,fin);

    //cin>>m>>n>>k;
    m = get_nr(), n = get_nr(), k = get_nr();
    for (i=1;i<=k;i++){
        //cin>>x>>y;
        x = get_nr(), y = get_nr();
        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;
    }

    fprintf(fout,"%d",sol);
    //cout<<sol;

    return 0;
}

Compilation message

marriage.cpp: In function 'int main()':
marriage.cpp:79:11: warning: ignoring return value of 'size_t fread(void*, size_t, size_t, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   79 |     fread (buff,1,DIMBUFF,fin);
      |     ~~~~~~^~~~~~~~~~~~~~~~~~~~
# 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 2 ms 1004 KB Output is correct
18 Correct 1 ms 1004 KB Output is correct
19 Correct 3 ms 1004 KB Output is correct
20 Correct 1 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 1 ms 1004 KB Output is correct
24 Correct 1 ms 1004 KB Output is correct
25 Correct 64 ms 1408 KB Output is correct
26 Correct 6 ms 1132 KB Output is correct
27 Correct 1 ms 1004 KB Output is correct
28 Correct 2 ms 1004 KB Output is correct
29 Correct 5 ms 1132 KB Output is correct
30 Correct 4 ms 1132 KB Output is correct
31 Correct 369 ms 1772 KB Output is correct
32 Correct 3 ms 1132 KB Output is correct
33 Correct 3 ms 1004 KB Output is correct
34 Correct 6 ms 1132 KB Output is correct
35 Correct 162 ms 2396 KB Output is correct
36 Correct 118 ms 2156 KB Output is correct
37 Correct 1196 ms 2028 KB Output is correct
38 Correct 37 ms 2412 KB Output is correct
39 Correct 201 ms 1260 KB Output is correct
40 Correct 94 ms 1260 KB Output is correct
41 Correct 54 ms 1516 KB Output is correct
42 Correct 552 ms 1516 KB Output is correct
43 Correct 816 ms 1900 KB Output is correct
44 Correct 1265 ms 2876 KB Output is correct
45 Correct 242 ms 1644 KB Output is correct
46 Correct 96 ms 2668 KB Output is correct
47 Execution timed out 1539 ms 2796 KB Time limit exceeded
48 Execution timed out 1576 ms 2796 KB Time limit exceeded
49 Correct 99 ms 2812 KB Output is correct
50 Correct 529 ms 1536 KB Output is correct