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 ll long long
#define pii pair<int, int>
using namespace std;
const int N = 2e5+1;
int n, cs, cf;
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin >> n >> cs >> cf;
// sol <= (n-2)!
vector<int> p(n);
iota(p.begin(), p.end(), 1);
int sol = 0;
do {
if (p[0] != cs || p[n-1] != cf) continue;
int f = p[0] < p[1];
cerr << p[0];
for (int i = 1; i < n; i++) {
cerr << p[i];
if (f && p[i-1] > p[i]) {f = -1; break;}
if (!f && p[i-1] < p[i]) {f = -1; break;}
f = !f;
}
cerr << endl;
if (f != -1) sol++;
} while (next_permutation(p.begin(), p.end()));
cout << sol;
}
# | 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... |