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

#TimeUsernameProblemLanguageResultExecution timeMemory
110848mosesmayerKangaroo (CEOI16_kangaroo)C++17
100 / 100
82 ms31992 KiB
#include <iostream> #include <iomanip> #include <cstring> using namespace std; typedef long long LL; const LL mod = 1e9 + 7; int n, s, t; LL dp[2005][2005]; LL f(int pos, int cc){ if (pos > n) return cc == 1; // base case, reached if cc = 1 when we reach end position if (pos > 1 && cc < 1) return 0; // once pos after 1, impossible as we have at least 1 contiguous component LL &ret = dp[pos][cc]; if (ret != -1) return ret; ret = 0; //special case --> endpoints if (!(pos ^ s) || !(pos ^ t)){ // UwU ಠ_ಠ (ret += f(pos + 1, cc)) %= mod; // already ada. (ret += f(pos + 1, cc + 1)) %= mod; // desired endpoint not used } else { int ends = 2 - (pos > s) - (pos > t); //new component --> two adjacent will be smaller (ret += f(pos + 1, cc + 1) * (cc - 1 + ends)) %= mod; // create new component, ends == extra empty spaces due to ends //merge component --> larger than two adjacent (ret += f(pos + 1, cc - 1) * (cc - 1)) %= mod; } return ret; } int main(){ cin >> n >> s >> t; memset(dp, -1, sizeof(dp)); cout << f(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...