| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1324269 | yousuf11 | Kangaroo (CEOI16_kangaroo) | C++20 | 7 ms | 15928 KiB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
int add(ll a, ll b) {
return (a%mod + b%mod + 2*mod)%mod;
}
int mul(ll a, ll b) {
return ((a%mod) * (b%mod)) % mod;
}
// 1 2 3
// 1 3 2
// 2 3 1
// 2 1 3
// 3 1 2
// 3 2 1
const int N = 2002;
int dp[N][N], n, st, en;
int rec(int i, int j) {
if (j < 0) return 0;
if (i == n) return (j == 1);
int&ret = dp[i][j];
// add new
if (i == st || i == en) {
ret = rec(i + 1, j + 1);
// push_front , back
if (j)
ret = add(ret, rec(i + 1, j));
}
else {
ret = mul(rec(i + 1, j + 1), j + 1 - (i > st) - (i > en));
// merge
if (j >= 2)
ret = add(ret, mul(rec(i + 1, j - 1), j - 1));
}
return ret;
}
// [] -> inc {i} -> dec [] -> always merge works -> there is no insert
// push_back -> cant do 2 i,i+1
inline void die() {
memset(dp, -1, sizeof(dp));
cin >> n >> st >> en;
--st, --en;
cout << rec(0,0) << "\n";
}
signed main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t = 1;
// cin >> t;
while (t--)
die();
}
Compilation message (stderr)
| # | 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... | ||||
