답안 #90026

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
90026 2018-12-19T17:58:39 Z Bodo171 결혼 문제 (IZhO14_marriage) C++14
80 / 100
1500 ms 2608 KB
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
const int nmax=30005;
vector<int> v[nmax];
int l[nmax],r[nmax];
bool viz[nmax];
bool changed;
int n,m,i,j,k,a,b,p,cupl,ans;
bool cup(int x)
{
    if(viz[x])
        return 0;
    viz[x]=1;
    for(int it=0;it<v[x].size();it++)
        if(!r[v[x][it]])
    {
        l[x]=v[x][it];
        r[v[x][it]]=x;
        return 1;
    }
    for(int it=0;it<v[x].size();it++)
        if(cup(r[v[x][it]]))
    {
        l[x]=v[x][it];
        r[v[x][it]]=x;
        return 1;
    }
    return 0;
}
void cc()
{
    changed=1;
    while(changed&&cupl<m)
    {
        changed=0;
        for(j=p; j<=i; j++)
            if((!l[j])&&cup(j))
            {
                cupl++;
                changed=1;
            }
        for(j=p; j<=i; j++)
            viz[j]=0;

    }
}
int main()
{
    //freopen("data.in","r",stdin);
    ios_base::sync_with_stdio(false);
    cin>>n>>m>>k;
    for(i=1;i<=k;i++)
    {
        cin>>a>>b;
        v[a].push_back(b);
    }
    for(i=1;i<=n;i++)
        sort(v[i].begin(),v[i].end());
    p=1;
    for(i=1;i<=n;i++)
    {
        if(i>=m)cc();
        while(cupl==m)
        {
            if(l[p])
                r[l[p]]=0,cupl--;
            p++;
            cc();

        }
        ans+=(p-1);
    }
    cout<<ans;
    return 0;
}

Compilation message

marriage.cpp: In function 'bool cup(int)':
marriage.cpp:17:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int it=0;it<v[x].size();it++)
                  ~~^~~~~~~~~~~~
marriage.cpp:24:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int it=0;it<v[x].size();it++)
                  ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1016 KB Output is correct
2 Correct 3 ms 1268 KB Output is correct
3 Correct 3 ms 1268 KB Output is correct
4 Correct 3 ms 1268 KB Output is correct
5 Correct 3 ms 1268 KB Output is correct
6 Correct 3 ms 1296 KB Output is correct
7 Correct 3 ms 1296 KB Output is correct
8 Correct 3 ms 1296 KB Output is correct
9 Correct 3 ms 1296 KB Output is correct
10 Correct 3 ms 1296 KB Output is correct
11 Correct 3 ms 1296 KB Output is correct
12 Correct 3 ms 1296 KB Output is correct
13 Correct 3 ms 1296 KB Output is correct
14 Correct 3 ms 1296 KB Output is correct
15 Correct 3 ms 1296 KB Output is correct
16 Correct 3 ms 1296 KB Output is correct
17 Correct 3 ms 1296 KB Output is correct
18 Correct 3 ms 1296 KB Output is correct
19 Correct 3 ms 1296 KB Output is correct
20 Correct 3 ms 1296 KB Output is correct
21 Correct 3 ms 1296 KB Output is correct
22 Correct 3 ms 1296 KB Output is correct
23 Correct 3 ms 1296 KB Output is correct
24 Correct 3 ms 1296 KB Output is correct
25 Correct 6 ms 1404 KB Output is correct
26 Correct 6 ms 1404 KB Output is correct
27 Correct 4 ms 1404 KB Output is correct
28 Correct 3 ms 1404 KB Output is correct
29 Correct 22 ms 1404 KB Output is correct
30 Correct 18 ms 1404 KB Output is correct
31 Correct 17 ms 1660 KB Output is correct
32 Correct 25 ms 1660 KB Output is correct
33 Correct 6 ms 1660 KB Output is correct
34 Correct 5 ms 1660 KB Output is correct
35 Correct 24 ms 1920 KB Output is correct
36 Correct 19 ms 1920 KB Output is correct
37 Correct 30 ms 1920 KB Output is correct
38 Correct 826 ms 2132 KB Output is correct
39 Correct 205 ms 2132 KB Output is correct
40 Correct 1230 ms 2132 KB Output is correct
41 Execution timed out 1568 ms 2132 KB Time limit exceeded
42 Execution timed out 1569 ms 2172 KB Time limit exceeded
43 Execution timed out 1569 ms 2172 KB Time limit exceeded
44 Execution timed out 1562 ms 2172 KB Time limit exceeded
45 Execution timed out 1567 ms 2176 KB Time limit exceeded
46 Execution timed out 1566 ms 2564 KB Time limit exceeded
47 Execution timed out 1570 ms 2564 KB Time limit exceeded
48 Execution timed out 1578 ms 2564 KB Time limit exceeded
49 Execution timed out 1568 ms 2608 KB Time limit exceeded
50 Execution timed out 1501 ms 2608 KB Time limit exceeded