Submission #1294026

#TimeUsernameProblemLanguageResultExecution timeMemory
1294026asimKangaroo (CEOI16_kangaroo)C++20
6 / 100
2094 ms572 KiB
#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;
    do{
        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);
    }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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...