Submission #488317

#TimeUsernameProblemLanguageResultExecution timeMemory
488317ExplodingFreezeKangaroo (CEOI16_kangaroo)C++17
100 / 100
22 ms22988 KiB
#include <bits/stdc++.h> #define int long long const int MOD = 1e9 + 7; using pii=std::pair<int,int>; using namespace std; const int maxn = 2005; int n, cs, cf, dp[maxn][maxn]; // dp[positions visited in first i steps][as j components] = number of ways of doing so int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> cs >> cf; cs--; cf--; dp[1][1] = 1; for(int i = 1; i < n; i++) for(int j = 1; j <= i; j++) { if(i == cs || i == cf) { // Add at start / end as expected, creating a new component if required dp[i + 1][j] += dp[i][j]; dp[i + 1][j] %= MOD; dp[i + 1][j + 1] += dp[i][j]; dp[i + 1][j + 1] %= MOD; } else { // Place as a seperate component dp[i + 1][j + 1] += (j + 1 - (i > cs) - (i > cf)) * dp[i][j]; dp[i + 1][j + 1] %= MOD; // Merge two components together dp[i + 1][j - 1] += (j - 1) * dp[i][j]; dp[i + 1][j - 1] %= MOD; } } 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...