#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
marriage.cpp: In function 'int main()':
marriage.cpp:82: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 |
1144 KB |
Output is correct |
2 |
Correct |
2 ms |
1276 KB |
Output is correct |
3 |
Correct |
3 ms |
1276 KB |
Output is correct |
4 |
Incorrect |
2 ms |
1276 KB |
Output isn't correct |
5 |
Incorrect |
3 ms |
1276 KB |
Output isn't correct |
6 |
Incorrect |
3 ms |
1276 KB |
Output isn't correct |
7 |
Correct |
2 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 |
1308 KB |
Output is correct |
11 |
Correct |
3 ms |
1308 KB |
Output is correct |
12 |
Correct |
3 ms |
1308 KB |
Output is correct |
13 |
Runtime error |
4 ms |
2124 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
14 |
Correct |
3 ms |
2124 KB |
Output is correct |
15 |
Correct |
3 ms |
2152 KB |
Output is correct |
16 |
Incorrect |
3 ms |
2152 KB |
Output isn't correct |
17 |
Correct |
3 ms |
2152 KB |
Output is correct |
18 |
Correct |
3 ms |
2152 KB |
Output is correct |
19 |
Correct |
3 ms |
2244 KB |
Output is correct |
20 |
Correct |
3 ms |
2244 KB |
Output is correct |
21 |
Correct |
3 ms |
2244 KB |
Output is correct |
22 |
Incorrect |
3 ms |
2316 KB |
Output isn't correct |
23 |
Correct |
3 ms |
2316 KB |
Output is correct |
24 |
Correct |
3 ms |
2316 KB |
Output is correct |
25 |
Correct |
6 ms |
2444 KB |
Output is correct |
26 |
Correct |
5 ms |
2444 KB |
Output is correct |
27 |
Correct |
4 ms |
2444 KB |
Output is correct |
28 |
Incorrect |
3 ms |
2444 KB |
Output isn't correct |
29 |
Correct |
21 ms |
2444 KB |
Output is correct |
30 |
Correct |
18 ms |
2532 KB |
Output is correct |
31 |
Runtime error |
16 ms |
3520 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
32 |
Correct |
23 ms |
3520 KB |
Output is correct |
33 |
Correct |
5 ms |
3520 KB |
Output is correct |
34 |
Incorrect |
5 ms |
3520 KB |
Output isn't correct |
35 |
Runtime error |
25 ms |
4028 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
36 |
Runtime error |
21 ms |
4044 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
37 |
Runtime error |
18 ms |
4044 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
38 |
Runtime error |
25 ms |
4620 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
39 |
Incorrect |
306 ms |
4620 KB |
Output isn't correct |
40 |
Correct |
1006 ms |
4620 KB |
Output is correct |
41 |
Execution timed out |
1544 ms |
4620 KB |
Time limit exceeded |
42 |
Execution timed out |
1553 ms |
4684 KB |
Time limit exceeded |
43 |
Runtime error |
18 ms |
4684 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
44 |
Runtime error |
26 ms |
4684 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
45 |
Execution timed out |
1553 ms |
4684 KB |
Time limit exceeded |
46 |
Runtime error |
33 ms |
5068 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
47 |
Runtime error |
31 ms |
5068 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
48 |
Runtime error |
28 ms |
5068 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
49 |
Runtime error |
36 ms |
5452 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
50 |
Execution timed out |
1566 ms |
5452 KB |
Time limit exceeded |