#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define int long long
#define pb push_back
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define endl "\n"
#define Yes cout << "YES" << endl;
#define No cout << "NO" << endl;
#define mod(a) ((a % MOD + MOD) % MOD)
#define inp(v) for(auto &a : v) cin >> a;
#define out(v) for(auto &a : v) cout << a << " ";
const int MOD = (int)1e9 + 7;
const int MAX = (int)1e5 + 5;
void solve() {
//x >> y = x / (2 ^ y)
//x << y = x * (2 ^ y)
int n,cs,cf;
cin >> n >> cs >> cf;
vector<int> vt;
for(int i = 1; i <= n; i++) {
vt.pb(i);
}
int say = 0;
int k = 0;
do{
if(k >= 4740000)break;
bool ok = true;
if(vt[0] != cs or vt[n - 1] != cf) {
ok = false;
}
for(int i = 1; i < vt.size() - 1; i++) {
if(!ok)break;
if(vt[i] < vt[i + 1] and vt[i - 1] < vt[i]) {
ok = false;
break;
}
if(vt[i] > vt[i + 1] and vt[i - 1] > vt[i]) {
ok = false;
break;
}
}
if(ok)say++;
mod(say);
k++;
}while(next_permutation(all(vt)));
cout << say << endl;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t = 1;
//cin >> t;
while (t--) {
solve();
}
}
| # | 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... |