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

#TimeUsernameProblemLanguageResultExecution timeMemory
376623thiago4532Kangaroo (CEOI16_kangaroo)C++17
100 / 100
61 ms32128 KiB
#include <bits/stdc++.h> #define int int64_t using namespace std; const int maxn = 2010; const int mod = 1e9 + 7; int dp[maxn][maxn]; int n; int ini, fim; int solve(int i, int k) { if (i > n && k == 1) return 1; else if (i > n) return 0; if (dp[i][k] != -1) return dp[i][k]; int caso1 = solve(i+1, k+1); int caso2 = (k ? (i == ini || i == fim ? solve(i+1, k) : solve(i+1, k-1)) : 0); if (i == ini || i == fim) return dp[i][k] = (caso1 + caso2)%mod; else if (i < ini && i < fim) return dp[i][k] = ( caso1*(k+1) + caso2*(k-1) )%mod; else if (i < ini || i < fim) return dp[i][k] = ( caso1*k + caso2*(k-1) )%mod; return dp[i][k] = ((k-1)*( caso1 + caso2 ))%mod; } int32_t main() { memset(dp, -1, sizeof dp); cin >> n; cin >> ini >> fim; cout << solve(1, 0) << '\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...