| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1293836 | darkdevilvaqif | Kangaroo (CEOI16_kangaroo) | C++20 | 0 ms | 0 KiB |
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
// #pragma GCC target("avx2")
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define ld long double
#define all(v, l) v.begin() + l, v.end()
#define rall(v, l) v.rbegin(), v.rend() - l
#define pb push_back
#define pf push_front
#define rsz resize
#define fi first
#define se second
#define LMAX LLONG_MAX
#define LMIN LLONG_MIN
#define IMAX INT_MAX
#define IMIN INT_MIN
#define endl "\n"
#define newline cout << endl;
using namespace std;
// structs
// globals
// variables
int n, s, e;
// iterators
int i;
// notes
/*
-stuff you should look for-
* int overflow, array bounds
* special cases (n=1?)
* do something instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
continue - skip the rest in the loop
*/
// functions
ll GCD(ll numeroune, ll numerodeux);
ll LCM(ll numeroune, ll numerodeux);
ll power(ll numeroune, ll numerodeux);
void solve()
{
cin >> n >> s >> e;
ans = 0;
vector <bool> used(n + 1, false);
used[s] = true;
function <void(int, int, int)> f = [&](int eaten, int v, int par)
{
if (eaten == n)
{
if (v == e)
{
ans++;
ans %= MOD;
}
return;
}
if (par < v)
{
for (int u = 1; u < v; u++)
{
if (used[u])
{
continue;
}
used[u] = true;
f(eaten + 1, u, v);
used[u] = false;
}
}
else
{
for (int u = v + 1; u <= n; u++)
{
if (used[u])
{
continue;
}
used[u] = true;
f(eaten + 1, u, v);
used[u] = false;
}
}
};
for (i = s + 1; i <= n; i++)
{
used[i] = true;
f(2, i, s);
used[i] = false;
}
for (i = 1; i < s; i++)
{
used[i] = true;
f(2, i, s);
used[i] = false;
}
cout << ans - 1;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
cin >> t;
while (t--)
{
solve();
newline
}
}
ll GCD(ll numeroune, ll numerodeux)
{
if (!numeroune)
{
return numerodeux;
}
return GCD(numerodeux % numeroune, numeroune);
}
ll LCM(ll numeroune, ll numerodeux)
{
return numeroune * numerodeux / GCD(numeroune, numerodeux);
}
ll power(ll numeroune, ll numerodeux)
{
ll res = 1;
while (numerodeux)
{
if (numerodeux & 1)
{
res *= numeroune;
}
numeroune *= numeroune;
numerodeux >>= 1;
}
return res;
}
/*
$$$$$$$$\ $$$$$$$$\
$$ _____|\____$$ |
$$ | $$ /
$$$$$\ $$ /
$$ __| $$ /
$$ | $$ /
$$$$$$$$\ $$$$$$$$\
\________|\________|
*/
