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 <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <set>
typedef long long llong;
const int MAXN = 2000 + 10;
const int MOD = 1e9 + 7;
const int INF = 1e9;
int n, m;
int perm[MAXN];
int pos[MAXN];
void solve()
{
int ans = 0;
for (int i = 1 ; i <= n ; ++i)
{
perm[2*i - 1] = i;
perm[2*i] = i;
}
do
{
bool valid = true;
std::fill(pos + 1, pos + 1 + n, 0);
for (int i = 1 ; i <= 2*n ; ++i)
{
if (pos[perm[i]] == 0)
{
pos[perm[i]] = i;
} else
{
if ((i - pos[perm[i]]) % m == 0)
{
valid = false;
break;
}
}
}
ans += valid;
} while(std::next_permutation(perm + 1, perm + 1 + 2*n));
std::cout << ans << '\n';
}
void read()
{
std::cin >> n >> m;
}
void fastIO()
{
std::ios_base :: sync_with_stdio(0);
std::cout.tie(nullptr);
std::cin.tie(nullptr);
}
int main()
{
fastIO();
read();
solve();
return 0;
}
# | 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... |