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;
int main(){
cin.tie(0);ios::sync_with_stdio(0);
//1.
int n, m;
//2.
cin >> n >> m;
vector < pair<int, int> > v(2 * n);
//3.
for(int i = 0; i < n; i++){
v[i].first = i + 1;
v[i].second = 1;
}
for(int i = 0; i < n; i++){
v[i + n].first = i + 1;
v[i + n].second = 2;
}
sort(v.begin(), v.end());
long long int f = 1;
for(int i = 1; i <= n * 2; i++) f *= i;
int p[n + 1];
long long int cnt = 0;
for(int i = 0; i < f; i++){
bool ok = 1;
for(int j = 0; j < n; j++) p[j + 1] = -1;
for(int j = 0; j < 2 * n; j++){
if(p[ v[j].first ] == -1) p[ v[j].first ] = j;
else{
if( (j - p[ v[j].first ]) % m == 0 ){
ok = 0;
break;
}
}
}
if(ok) cnt++;
next_permutation(v.begin(), v.end());
}
cout << cnt << endl;
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... |