(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 #399410

#TimeUsernameProblemLanguageResultExecution timeMemory
399410couplefireKangaroo (CEOI16_kangaroo)C++17
100 / 100
22 ms14076 KiB
#include <bits/stdc++.h> using namespace std; const int N = 2000+5; const int MOD = 1000000007; inline int add(int a, int b){return (a+b>=MOD)?a+b-MOD:a+b;} inline void inc(int& a, int b){a = add(a, b);} inline int sub(int a, int b){return (a-b<0)?a-b+MOD:a-b;} inline void dec(int &a, int b){a = sub(a, b);} inline int mul(int a, int b){return 1ll*a*b%MOD;} inline void grow(int &a, int b){a = mul(a, b);} int n, cs, cf; int dp[N][N]; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> cs >> cf; if(cs > cf) cs = n+1-cs, cf = n+1-cf; dp[0][0] = 1; for(int i = 1; i<cs; i++) for(int j = 1; j<=i; j++) inc(dp[i][j], add(mul(dp[i-1][j+1], j), mul(dp[i-1][j-1], j))); for(int j = 1; j<=cs; j++) inc(dp[cs][j], add(dp[cs-1][j], dp[cs-1][j-1])); for(int i = cs+1; i<cf; i++) for(int j = 1; j<=i; j++) inc(dp[i][j], add(mul(dp[i-1][j+1], j), mul(dp[i-1][j-1], j-1))); for(int j = 1; j<=cf; j++) inc(dp[cf][j], add(dp[cf-1][j], dp[cf-1][j-1])); for(int i = cf+1; i<=n; i++) for(int j = 1; j<=i; j++) inc(dp[i][j], add(mul(dp[i-1][j+1], j), mul(dp[i-1][j-1], j-2))); cout << dp[n][1] << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...