Submission #110848

#TimeUTC-0UsernameProblemLanguageResultExecution timeMemory
1108482019-05-12 13:14:22mosesmayerKangaroo (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;
}
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...