# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
90028 | Bodo171 | Marriage questions (IZhO14_marriage) | C++14 | 1566 ms | 5452 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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();*/
cin>>a>>b;
v[a].push_back(b);
}
for(i=1;i<=k;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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |