# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
93421 | inom | Marriage questions (IZhO14_marriage) | C++14 | 1584 ms | 2936 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 fi first
#define se second
#define pb push_back
#define int long long
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
using namespace std;
const int N = 30030;
int TN = 1;
int n, m, k;
int cnt, ans;
int us[N][55];
bool flag = false;
vector<int> verr[N];
void rec(int a, int b, int cnt, int pos) {
if (a > b) {
if (cnt >= m) {
flag = true; return;
} else {
return;
}
}
if (cnt >= m) {
flag = true; return;
}
for (int i: verr[a]) {
if (!us[pos][i]) {
us[pos][i] = 1;
rec(a + 1, b, cnt + 1, pos);
us[pos][i] = 0;
}
}
rec(a + 1, b, cnt, pos);
}
void solve() {
scanf("%lld %lld %lld", &n, &m, &k);
for (int i = 1; i <= k; i++) {
int x, y;
scanf("%lld %lld", &x, &y); verr[x].push_back(y);
}
int pos = 0;
for (int i = 1; i <= n; i++) {
int l = i, r = n;
while (l + 1 < r) {
int mid = (l + r) >> 1;
if (mid - i + 1 < m) {
l = mid + 1; continue;
}
flag = false; cnt = 0; pos++;
rec(i, mid, cnt, pos);
if (flag) {
r = mid;
} else {
l = mid + 1;
}
}
flag = false; cnt = 0; pos++;
rec(i, r, cnt, pos);
if (!flag) {
continue;
}
flag = false; cnt = 0; pos++;
rec(i, l, cnt, pos);
if (flag) {
ans += (n - l + 1);
} else {
ans += (n - r + 1);
}
// cout << i << " " << l << " " << r << "\n";
/*for (int r = l + m - 1; r <= n; r++) {
flag = false; cnt = 0;
rec(l, r, cnt, ans + 1); ans += flag;
if (flag) {
ans += (n - r); break;
}
}*/
}
printf("%lld\n", ans);
return;
}
signed main() {
// in; out; // cin >> TN;
while (TN--) { solve(); }
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |