답안 #31474

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
31474 2017-08-28T20:26:37 Z hamlet 결혼 문제 (IZhO14_marriage) C++14
40 / 100
1500 ms 4636 KB
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
using namespace std;
vector <int> a[30010],b[2010];
bool used[30010],used2[2010];
int mt[2010],nt[30010];
bool try_kuhn(int x)
{
    if (used[x]) return false;
    used[x]=true;
    int i;
    for (i=0;i<a[x].size();i++)
    if (mt[a[x][i]]==0 || try_kuhn(mt[a[x][i]]))
    {
        mt[a[x][i]]=x;
        nt[x]=a[x][i];
        return true;
    }
    return false;
}
int l,r=0;
bool try_kuhn2(int x)
{
    if (used2[x]) return false;
    used2[x]=true;
    int i;
    for (i=0;i<b[x].size();i++)
    if (b[x][i]>l && b[x][i]<=r && nt[b[x][i]]==0 || try_kuhn(nt[b[x][i]]))
    {
        nt[b[x][i]]=x;
        mt[x]=b[x][i];
        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);
        a[x].push_back(y);
        b[y].push_back(x);
    }
    int ans=0,p=0;
    for (l=1;l<=n-m+1;l++)
    {
        while (p!=m && r<n)
        {
            r++;
            memset(used,0,sizeof used);
            p+=try_kuhn(r);
        }
        if (p==m) ans+=n-r+1;
        if (nt[l]==0) continue;
        memset(used2,0,sizeof used2);
        x=nt[l];
        mt[nt[l]]=0;
        nt[l]=0;
        p--;
        p+=try_kuhn2(x);
    }
    printf("%d\n",ans);
    return 0;
}

Compilation message

marriage.cpp: In function 'bool try_kuhn(int)':
marriage.cpp:14:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i=0;i<a[x].size();i++)
               ^
marriage.cpp: In function 'bool try_kuhn2(int)':
marriage.cpp:29:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i=0;i<b[x].size();i++)
               ^
marriage.cpp:30:33: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
     if (b[x][i]>l && b[x][i]<=r && nt[b[x][i]]==0 || try_kuhn(nt[b[x][i]]))
                                 ^
marriage.cpp: In function 'int main()':
marriage.cpp:41: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:44: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 2920 KB Output isn't correct
2 Incorrect 0 ms 2920 KB Output isn't correct
3 Correct 0 ms 2920 KB Output is correct
4 Correct 0 ms 2920 KB Output is correct
5 Correct 0 ms 2920 KB Output is correct
6 Correct 0 ms 2920 KB Output is correct
7 Incorrect 0 ms 2920 KB Output isn't correct
8 Correct 0 ms 2920 KB Output is correct
9 Correct 0 ms 2920 KB Output is correct
10 Correct 0 ms 2920 KB Output is correct
11 Correct 0 ms 2920 KB Output is correct
12 Correct 0 ms 2920 KB Output is correct
13 Correct 0 ms 2920 KB Output is correct
14 Incorrect 0 ms 2920 KB Output isn't correct
15 Incorrect 0 ms 2920 KB Output isn't correct
16 Correct 0 ms 2920 KB Output is correct
17 Incorrect 0 ms 2920 KB Output isn't correct
18 Incorrect 0 ms 2920 KB Output isn't correct
19 Incorrect 0 ms 2920 KB Output isn't correct
20 Incorrect 0 ms 2920 KB Output isn't correct
21 Correct 0 ms 2920 KB Output is correct
22 Correct 0 ms 2920 KB Output is correct
23 Incorrect 0 ms 2920 KB Output isn't correct
24 Incorrect 0 ms 2920 KB Output isn't correct
25 Incorrect 3 ms 3052 KB Output isn't correct
26 Incorrect 3 ms 2920 KB Output isn't correct
27 Correct 0 ms 2920 KB Output is correct
28 Correct 0 ms 2920 KB Output is correct
29 Incorrect 3 ms 3052 KB Output isn't correct
30 Incorrect 3 ms 3052 KB Output isn't correct
31 Incorrect 16 ms 3448 KB Output isn't correct
32 Incorrect 16 ms 3052 KB Output isn't correct
33 Correct 0 ms 2920 KB Output is correct
34 Correct 3 ms 2920 KB Output is correct
35 Incorrect 93 ms 3976 KB Output isn't correct
36 Incorrect 123 ms 3976 KB Output isn't correct
37 Incorrect 43 ms 3712 KB Output isn't correct
38 Incorrect 226 ms 4240 KB Output isn't correct
39 Correct 49 ms 3084 KB Output is correct
40 Correct 6 ms 3184 KB Output is correct
41 Incorrect 106 ms 3316 KB Output isn't correct
42 Incorrect 243 ms 3580 KB Output isn't correct
43 Incorrect 319 ms 3712 KB Output isn't correct
44 Incorrect 813 ms 4108 KB Output isn't correct
45 Incorrect 33 ms 3712 KB Output isn't correct
46 Execution timed out 1500 ms 4504 KB Execution timed out
47 Execution timed out 1500 ms 4372 KB Execution timed out
48 Execution timed out 1500 ms 4372 KB Execution timed out
49 Execution timed out 1500 ms 4636 KB Execution timed out
50 Correct 56 ms 3084 KB Output is correct