답안 #38588

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
38588 2018-01-04T21:15:01 Z alenam0161 결혼 문제 (IZhO14_marriage) C++14
56 / 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_kuhn(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_kuhn(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);
                            ^
# 결과 실행 시간 메모리 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 Incorrect 0 ms 3232 KB Output isn't 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 Incorrect 0 ms 3232 KB Output isn't correct
20 Incorrect 0 ms 3232 KB Output isn't correct
21 Correct 0 ms 3232 KB Output is correct
22 Correct 0 ms 3232 KB Output is correct
23 Correct 0 ms 3232 KB Output is correct
24 Correct 0 ms 3232 KB Output is correct
25 Incorrect 6 ms 3364 KB Output isn't 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 3 ms 3364 KB Output isn't correct
30 Incorrect 3 ms 3364 KB Output isn't correct
31 Correct 23 ms 3760 KB Output is correct
32 Incorrect 13 ms 3364 KB Output isn't correct
33 Correct 0 ms 3232 KB Output is correct
34 Correct 3 ms 3232 KB Output is correct
35 Correct 99 ms 4288 KB Output is correct
36 Correct 76 ms 4288 KB Output is correct
37 Incorrect 46 ms 4024 KB Output isn't correct
38 Incorrect 229 ms 4552 KB Output isn't correct
39 Correct 63 ms 3364 KB Output is correct
40 Correct 29 ms 3496 KB Output is correct
41 Incorrect 46 ms 3628 KB Output isn't correct
42 Incorrect 249 ms 3892 KB Output isn't correct
43 Incorrect 223 ms 4024 KB Output isn't correct
44 Incorrect 743 ms 4420 KB Output isn't correct
45 Incorrect 73 ms 4024 KB Output isn't correct
46 Execution timed out 1500 ms 4816 KB Execution timed out
47 Incorrect 1059 ms 4684 KB Output isn't correct
48 Incorrect 1159 ms 4684 KB Output isn't correct
49 Execution timed out 1500 ms 4948 KB Execution timed out
50 Correct 99 ms 3368 KB Output is correct