# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
392540 | patrikpavic2 | 결혼 문제 (IZhO14_marriage) | C++17 | 1590 ms | 3332 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cstdio>
#include <cstring>
#include <vector>
#define PB push_back
using namespace std;
typedef long long ll;
const int N = (1 << 15);
int par[N], n, m, bio[N], k, un[N], cookie = 1;
vector < int > v[N];
bool dodaj(int x){
if(bio[x] == cookie) return 0;
bio[x] = cookie;
for(int y : v[x]){
if(un[y] && (par[y] == -1 || dodaj(par[y]))){
par[x] = y; par[y] = x;
return 1;
}
}
return 0;
}
int main(){
scanf("%d%d%d", &n, &m, &k);
for(int i = 0;i < k;i++){
int a, b; scanf("%d%d", &a, &b);
a--; b--;
v[a].PB(n + b), v[b + n].PB(a);
//printf("VEZA %d %d\n", a, b + n);
}
memset(par, -1, sizeof(par));
for(int i = 0;i < m;i++) un[i + n] = 1;
int r = 0, sol = 0;
ll ans = 0;
for(int l = 0;l < n;l++){
if(l){
un[l - 1] = 0;
if(par[l - 1] != -1){
sol--; par[par[l - 1]] = -1;
sol += dodaj(par[l - 1]); cookie++;
}
}
while(r < n && sol < m){
un[r] = 1; sol += dodaj(r); cookie++;
r++;
}
//printf("l = %d r = %d sol = %d\n", l, r, sol);
ans += (n + 1 - r) * (sol == m);
}
printf("%lld\n", ans);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |