# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
93414 | inom | Marriage questions (IZhO14_marriage) | C++14 | 1582 ms | 2808 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);
}
for (int l = 1; l <= n; l++) {
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... |