# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
167982 | Trickster | Marriage questions (IZhO14_marriage) | C++14 | 892 ms | 2780 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.
//Suleyman Atayew
#include <algorithm>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#define N 30010
#define ff first
#define ss second
#define pb push_back
#define ll long long
#define inf 1000000007
#define pii pair <int, int>
using namespace std;
int now;
int a, b;
int l, r;
int T[N];
int v[N];
int n, m, k;
queue <int> Q;
vector <int> E[N];
int dfs(int x)
{
if(v[x] == now) return 0;
v[x] = now;
for(auto i: E[x])
if(i >= l && i <= r)
if(T[i] == 0 || dfs(T[i])) return T[i] = x, 1;
return 0;
}
void tap()
{
while(Q.size()) {
int a = Q.front();
Q.pop(), now++;
if(!dfs(a)) {
Q.push(a);
break;
}
}
}
int main()
{
scanf("%d%d%d", &n, &m, &k);
for(int i = 1; i <= k; i++) {
scanf("%d%d", &a, &b);
E[b].pb(a);
}
for(int i = 1; i <= m; i++) Q.push(i);
int ans = 0;
for(l = 1; l <= n; l++) {
r = max(r, l);
tap();
while(r < n && Q.size()) r++, tap();
if(Q.size()) break;
ans += n-r+1;
if(T[l]) Q.push(T[l]), T[l] = 0;
}
printf("%d", ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |