Submission #38589

# Submission time Handle Problem Language Result Execution time Memory
38589 2018-01-04T21:15:53 Z alenam0161 Marriage questions (IZhO14_marriage) C++14
66 / 100
1500 ms 4948 KB
#include<bits/stdc++.h>

#define ad push_back

using namespace std;
const int N = 40007 , M = 3007;
vector <int> g[N],g1[M];
bool used1[N],used2[M];
int ma[M],na[N];
bool try_kuhn(int x)
{
    if (used1[x]) return false;
    used1[x]=true;
    int i;
    for (auto to:g[x])
    if (ma[to]==0 || try_kuhn(ma[to]))
    {
        ma[to]=x;
        na[x]=to;
        return true;
    }
    return false;
}
int l,r=0;
bool try_kuhn2(int x)
{
    if (used2[x]) return false;
    used2[x]=true;
    int i;
    for (auto to:g1[x])
    if (to>l && to<=r && na[to]==0 || try_kuhn2(na[to]))
    {
        na[to]=x;
        ma[x]=to;
        return true;
    }
    return false;
}
int main()
{
    int i,n,m,k,x,y;
    scanf("%d%d%d",&n,&m,&k);
    for (i=1;i<=k;i++)
    {
        scanf("%d%d",&x,&y);
        g[x].ad(y);
        g1[y].ad(x);
    }
    long long ans=0;
    int how=0;
    for (l=1;l<=n-m+1;l++)
    {
        while (how!=m && r<n)
        {
            r++;
            memset(used1,0,sizeof used1);
            how+=try_kuhn(r);
        }
        if ( how == m ) ans += n - r + 1;
        if (na[l]==0) continue;
        memset(used2,0,sizeof( used2));
        int gag=na[l];
        ma[na[l]]=0;
        na[l]=0;
        how--;
        how+=try_kuhn2(x);
    }
    cout<<ans<<"\n";
    return 0;
}

Compilation message

marriage.cpp: In function 'bool try_kuhn(int)':
marriage.cpp:14:9: warning: unused variable 'i' [-Wunused-variable]
     int i;
         ^
marriage.cpp: In function 'bool try_kuhn2(int)':
marriage.cpp:31:23: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
     if (to>l && to<=r && na[to]==0 || try_kuhn2(na[to]))
                       ^
marriage.cpp:29:9: warning: unused variable 'i' [-Wunused-variable]
     int i;
         ^
marriage.cpp: In function 'int main()':
marriage.cpp:62:13: warning: unused variable 'gag' [-Wunused-variable]
         int gag=na[l];
             ^
marriage.cpp:42:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d",&n,&m,&k);
                             ^
marriage.cpp:45:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&x,&y);
                            ^
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 3232 KB Output isn't correct
2 Incorrect 0 ms 3232 KB Output isn't correct
3 Correct 0 ms 3232 KB Output is correct
4 Correct 0 ms 3232 KB Output is correct
5 Correct 0 ms 3232 KB Output is correct
6 Correct 0 ms 3232 KB Output is correct
7 Correct 0 ms 3232 KB Output is correct
8 Correct 0 ms 3232 KB Output is correct
9 Correct 0 ms 3232 KB Output is correct
10 Correct 0 ms 3232 KB Output is correct
11 Correct 0 ms 3232 KB Output is correct
12 Correct 0 ms 3232 KB Output is correct
13 Correct 0 ms 3232 KB Output is correct
14 Correct 0 ms 3232 KB Output is correct
15 Incorrect 0 ms 3232 KB Output isn't correct
16 Correct 0 ms 3232 KB Output is correct
17 Correct 0 ms 3232 KB Output is correct
18 Correct 0 ms 3232 KB Output is correct
19 Correct 0 ms 3232 KB Output is correct
20 Correct 0 ms 3232 KB Output is correct
21 Correct 0 ms 3232 KB Output is correct
22 Correct 0 ms 3232 KB Output is correct
23 Correct 3 ms 3232 KB Output is correct
24 Correct 0 ms 3232 KB Output is correct
25 Correct 53 ms 3364 KB Output is correct
26 Incorrect 3 ms 3232 KB Output isn't correct
27 Correct 0 ms 3232 KB Output is correct
28 Correct 0 ms 3232 KB Output is correct
29 Incorrect 6 ms 3364 KB Output isn't correct
30 Incorrect 3 ms 3364 KB Output isn't correct
31 Correct 16 ms 3760 KB Output is correct
32 Incorrect 9 ms 3364 KB Output isn't correct
33 Correct 3 ms 3232 KB Output is correct
34 Correct 3 ms 3232 KB Output is correct
35 Correct 96 ms 4288 KB Output is correct
36 Correct 83 ms 4288 KB Output is correct
37 Correct 933 ms 4024 KB Output is correct
38 Incorrect 269 ms 4552 KB Output isn't correct
39 Correct 66 ms 3364 KB Output is correct
40 Correct 29 ms 3496 KB Output is correct
41 Incorrect 49 ms 3628 KB Output isn't correct
42 Incorrect 209 ms 3892 KB Output isn't correct
43 Incorrect 283 ms 4024 KB Output isn't correct
44 Incorrect 759 ms 4420 KB Output isn't correct
45 Incorrect 76 ms 4024 KB Output isn't correct
46 Execution timed out 1500 ms 4816 KB Execution timed out
47 Incorrect 1199 ms 4684 KB Output isn't correct
48 Incorrect 1186 ms 4684 KB Output isn't correct
49 Execution timed out 1500 ms 4948 KB Execution timed out
50 Correct 96 ms 3368 KB Output is correct