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 <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
bool check(int x, int y, int z) {
if((x < y && z < y) || (y < x && y < z)) return true;
return false;
}
int main() {
ll n, cs, cf, temp = 0;
bool ok;
const ll MOD = 1e9+7;
cin >> n >> cs >> cf;
vector<int> a(n);
for(int i = 1; i <= n; i++) a[i-1] = i;
do {
ok = true;
for(int i = 2; i < n; i++) {
if(!check(a[i-2], a[i-1], a[i])) {
ok = false;
break;
}
}
if(a[0] == cs && a[n-1] == cf && ok) temp = (temp+1)%MOD;
} while(next_permutation(a.begin(), a.end()));
cout << temp << "\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... |