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>
using namespace std;
typedef pair<int, int> pii;
int n, mod;
bool chosen[16];
int ans = 0;
bool works(vector<pii> &v) {
vector<pii> s, t;
for (int i = 0; i < n; i++) {
s.push_back(pii(v[i].first, i));
t.push_back(pii(v[i].second, i));
}
sort(s.begin(), s.end());
sort(t.begin(), t.end());
int a = 0, b = 0;
int r = -1;
for (int i = 0; i < n; i++) {
if (s[i].first < r) continue;
a++;
r = v[s[i].second].second;
}
r = -1;
for (int i = 0; i < n; i++) {
if (v[t[i].second].first < r) continue;
b++;
r = t[i].first;
}
return b > a;
}
void make(vector<pii> &v, int cur = 0) {
if (cur == n) {
ans += works(v);
return;
}
for (int i = 0; i < 2*n; i++) {
if (chosen[i]) continue;
chosen[i] = 1;
for (int j = i+1; j < 2*n; j++) {
if (chosen[j]) continue;
chosen[j] = 1;
v.push_back(pii(i, j));
make(v, cur+1);
v.pop_back();
chosen[j] = 0;
}
chosen[i] = 0;
return;
}
}
int main() {
cin >> n >> mod;
assert(n <= 8);
vector<pii> v;
make(v);
cout << ans%mod << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |