# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
87266 | Yaroslaff | Marriage questions (IZhO14_marriage) | C++14 | 1127 ms | 13828 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 pb push_back
#define F first
#define S second
#define ll long long
//#define int ll
#define x1 epgjoijhgoj
#define y1 epggoijhgoj
#define ld double
#define endl '\n'
#define TIME 1.0*clock()/CLOCKS_PER_SEC
using namespace std;
mt19937 gen(chrono::system_clock::now().time_since_epoch().count());
const int M = 1e9 + 7;
const int MOD = 998244353;
const int N = 1e5 + 10;
int n, m, k, x, y, l, r, u[N], cur, res, p[N];
vector<int> g[N], mt(N, -1), us;
bool par(int v) {
for (int i = p[v]; i < g[v].size(); i++) {
int to = g[v][i];
if (to < l) p[v]++;
if (to >= r) return 0;
if (us[to] || to < l) continue;
us[to] = 1;
if (mt[to] == -1 || par(mt[to])) {
mt[to] = v;
return 1;
}
}
return 0;
}
void kun() {
us.assign(n + 2, 0);
for (int i = 0; i < m; i++) {
if (!u[i] && par(i)) {
u[i] = 1;
cur++;
return;
}
}
}
void add() {
++r;
kun();
}
void del() {
if (mt[l] != -1) {
u[mt[l]] = 0;
--cur;
}
l++;
if (cur < m) kun();
}
main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifdef LOCAL
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
cin >> n >> m >> k;
for (int i = 0; i < k; i++) {
cin >> x >> y;--x;--y;
g[y].pb(x);
}
for (int i = 0; i < N; i++)
sort(g[i].begin(), g[i].end());
for (; 1;) {
while (r < n && cur < m) add();
if (cur != m) break;
res += n - r + 1;
del();
}
cout << res;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |