# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
363492 | nicolaalexandra | Marriage questions (IZhO14_marriage) | C++14 | 1592 ms | 3052 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 <bits/stdc++.h>
#define DIM 30010
using namespace std;
vector <int> L[DIM];
bitset <DIM> f;
int Left[DIM],Right[DIM];
int n,m,k,i,x,y,cnt;
int cupleaza (int nod, int x, int y){
if (f[nod])
return 0;
f[nod] = 1;
for (auto vecin : L[nod]){
if (!(vecin >= x && vecin <= y))
continue;
if (!Right[vecin]){
Right[vecin] = nod;
Left[nod] = vecin;
cnt++;
return 1;
}
}
for (auto vecin : L[nod]){
if (!(vecin >= x && vecin <= y))
continue;
if (cupleaza (Right[vecin],x,y)){
Left[nod] = vecin;
Right[vecin] = nod;
return 1;
}
}
return 0;
}
int cuplaj (int x, int y){
memset (Left,0,sizeof Left);
memset (Right,0,sizeof Right);
int ok = 0;
cnt = 0;
do{
f.reset();
ok = 0;
for (int i=1;i<=n;i++){
if (!Left[i] && cupleaza (i,x,y))
ok = 1;
}
} while (ok);
return cnt;
}
int main (){
//ifstream cin ("date.in");
//ofstream cout ("date.out");
cin>>m>>n>>k;
for (i=1;i<=k;i++){
cin>>x>>y;
L[y].push_back(x);
}
int sol = 0;
for (i=n;i<=m;i++){
int st = 1, dr = i, poz = 0;
while (st <= dr){
int mid = (st+dr)>>1;
if (cuplaj(mid,i) == n){
poz = mid;
st = mid+1;
} else dr = mid-1;
}
sol += poz;
}
cout<<sol;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |