(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

Submission #443656

#TimeUsernameProblemLanguageResultExecution timeMemory
443656fsociety00Kangaroo (CEOI16_kangaroo)C++14
100 / 100
38 ms15988 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long int #define LD long double const int N = 100010; int inf = 1e9; int mod = 1e9 + 7; inline void add(int &a, int b) { a += b; if (a >= mod) a -= mod; } inline void sub(int &a, int b) { a -= b; if (a < 0) a += mod; } inline int mul(int a, int b) { return (int) ((long long) a * b % mod); } inline int power(int a, long long b) { int res = 1; while (b > 0) { if (b & 1) { res = mul(res, a); } a = mul(a, a); b >>= 1; } return res; } inline int inv(int a) { a %= mod; if (a < 0) a += mod; int b = mod, u = 0, v = 1; while (a) { int t = b / a; b -= t * a; swap(a, b); u -= t * v; swap(u, v); } assert(b == 1); if (u < 0) u += mod; return u; } signed main() { // freopen("kangaroo.in", "r", stdin); // freopen("kangaroo.out", "w", stdout); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; int cs, cf; cin >> cs >> cf; int dp[n + 1][n + 2]; memset(dp, 0, sizeof(dp)); dp[1][1] = 1; for (int i = 2; i <= n; i++) { for (int j = 1; j <= i; j++) { if (i == cs || i == cf) { add(dp[i][j], dp[i - 1][j - 1]); add(dp[i][j], dp[i - 1][j]); continue; } add(dp[i][j], mul(j, dp[i - 1][j + 1])); int ins = j; if (i > cs) sub(ins, 1); if (i > cf) sub(ins, 1); add(dp[i][j], mul(ins, dp[i - 1][j - 1])); } } cout << dp[n][1] << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...