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;
#define forn(i,n) for (int i=0; i<n; ++i)
void solve() {
int n,m; cin>>n>>m;
if (n>5) return;
vector<int>vis(2*n+1,0);
vector<int>s;
forn(i,2*n) s.push_back(i+1);
int steps=0;
int ans=0;
next_permutation(s.begin(), s.end());
while (1) {
int paiu=1;
forn(i,2*n) {
for (int k=i%m; k<2*n; k+=m) {
if (k==i) continue;
if (abs(s[k]-s[i])==n) paiu=0;
}
}
ans+=paiu;
int scuza=1;
for (int i=0; i<2*n; ++i) {
scuza&=(i+1)==s[i];
}
if (scuza) break;
next_permutation(s.begin(), s.end());
}
cout<<ans;
//cout<<" !"<<steps;
}
int32_t main() {
solve();
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'void solve()':
Main.cpp:12:6: warning: unused variable 'steps' [-Wunused-variable]
12 | int steps=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... |