답안 #90029

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
90029 2018-12-19T18:07:38 Z Bodo171 결혼 문제 (IZhO14_marriage) C++14
72 / 100
1500 ms 5252 KB
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
const int nmax=30005;
const int mmax=100005;
vector<int> v[nmax];
int l[nmax],r[nmax],L[nmax],R[nmax];
int ls[nmax];
bool viz[nmax];
bool changed;
int n,m,i,j,k,a,b,p,cupl,ans,nr;
bool cup(int x)
{
    if(viz[x])
        return 0;
    viz[x]=1;
    for(int it=L[x];it<=R[x];it++)
        if(!r[ls[it]])
    {
        l[x]=ls[it];
        r[ls[it]]=x;
        return 1;
    }
    for(int it=L[x];it<=R[x];it++)
        if(cup(r[ls[it]]))
    {
        l[x]=ls[it];
        r[ls[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 ch,num;
string s;
int getnum()
{
    num=0;
    while(s[ch]>='0'&&s[ch]<='9')
    {
        num=num*10+s[ch]-'0';
        ch++;
    }
    ch++;
    return num;
}
int main()
{
    //freopen("data.in","r",stdin);
    ios_base::sync_with_stdio(false);
    cin>>n>>m>>k;
    getline(cin,s);
    for(i=1;i<=k;i++)
    {
        getline(cin,s);ch=0;
        a=getnum();b=getnum();
        v[a].push_back(b);
    }
    for(i=1;i<=n;i++)
    {
        L[i]=nr+1;
        for(j=0;j<v[i].size();j++)
        {
            ls[++nr]=v[i][j];
        }
        R[i]=nr;
    }
    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 'int main()':
marriage.cpp:81:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(j=0;j<v[i].size();j++)
                 ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1016 KB Output is correct
2 Correct 3 ms 1276 KB Output is correct
3 Correct 3 ms 1276 KB Output is correct
4 Correct 3 ms 1276 KB Output is correct
5 Correct 3 ms 1276 KB Output is correct
6 Correct 3 ms 1276 KB Output is correct
7 Correct 3 ms 1276 KB Output is correct
8 Correct 3 ms 1276 KB Output is correct
9 Correct 3 ms 1276 KB Output is correct
10 Correct 3 ms 1296 KB Output is correct
11 Correct 3 ms 1312 KB Output is correct
12 Correct 3 ms 1312 KB Output is correct
13 Correct 3 ms 1312 KB Output is correct
14 Correct 3 ms 1312 KB Output is correct
15 Correct 2 ms 1312 KB Output is correct
16 Correct 2 ms 1344 KB Output is correct
17 Correct 2 ms 1344 KB Output is correct
18 Correct 2 ms 1344 KB Output is correct
19 Correct 3 ms 1384 KB Output is correct
20 Correct 2 ms 1384 KB Output is correct
21 Correct 3 ms 1384 KB Output is correct
22 Correct 2 ms 1384 KB Output is correct
23 Correct 3 ms 1384 KB Output is correct
24 Correct 3 ms 1384 KB Output is correct
25 Correct 4 ms 1404 KB Output is correct
26 Correct 5 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 19 ms 1404 KB Output is correct
30 Correct 17 ms 1452 KB Output is correct
31 Incorrect 10 ms 1904 KB Output isn't correct
32 Correct 22 ms 1904 KB Output is correct
33 Correct 5 ms 1904 KB Output is correct
34 Correct 5 ms 1904 KB Output is correct
35 Runtime error 90 ms 4316 KB Execution killed with signal 11 (could be triggered by violating memory limits)
36 Incorrect 40 ms 4316 KB Output isn't correct
37 Incorrect 29 ms 4316 KB Output isn't correct
38 Runtime error 266 ms 4796 KB Execution killed with signal 11 (could be triggered by violating memory limits)
39 Correct 191 ms 4796 KB Output is correct
40 Correct 1008 ms 4796 KB Output is correct
41 Execution timed out 1557 ms 4796 KB Time limit exceeded
42 Execution timed out 1565 ms 4796 KB Time limit exceeded
43 Execution timed out 1571 ms 4796 KB Time limit exceeded
44 Runtime error 342 ms 4800 KB Execution killed with signal 11 (could be triggered by violating memory limits)
45 Execution timed out 1554 ms 4800 KB Time limit exceeded
46 Execution timed out 1561 ms 4800 KB Time limit exceeded
47 Runtime error 1427 ms 5252 KB Execution killed with signal 11 (could be triggered by violating memory limits)
48 Runtime error 1297 ms 5252 KB Execution killed with signal 11 (could be triggered by violating memory limits)
49 Execution timed out 1551 ms 5252 KB Time limit exceeded
50 Correct 1355 ms 5252 KB Output is correct