Submission #490496

#TimeUsernameProblemLanguageResultExecution timeMemory
490496Yazan_AlattarKangaroo (CEOI16_kangaroo)C++14
100 / 100
153 ms126016 KiB
#include <iostream> #include <fstream> #include <vector> #include <cstring> #include <algorithm> #include <set> #include <map> #include <queue> #include <list> #include <utility> #include <cmath> #include <numeric> using namespace std; typedef long long ll; #define F first #define S second #define pb push_back #define endl "\n" #define all(x) x.begin(), x.end() const int M = 2007; const ll inf = 1e18; const ll mod = 1e9 + 7; const double pi = acos(-1); const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}; ll n, st, en, dp[M][M][2][2]; int main() { ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> n >> st >> en; dp[0][0][0][0] = 1; for(int i = 1; i <= n; ++i){ for(int j = 1; j <= n; ++j){ for(int on1 = 0; on1 < 2; ++on1){ for(int on2 = 0; on2 < 2; ++on2){ if(i == st){ if(on1) continue; dp[i][j][1][on2] = (dp[i - 1][j][0][on2] + dp[i - 1][j - 1][0][on2]) % mod; } else if(i == en){ if(on2) continue; dp[i][j][on1][1] = (dp[i - 1][j][on1][0] + dp[i - 1][j - 1][on1][0]) % mod; } else{ dp[i][j][on1][on2] = (dp[i - 1][j - 1][on1][on2] * (j - on1 - on2)) % mod; dp[i][j][on1][on2] += (dp[i - 1][j + 1][on1][on2] * j) % mod; } } } } } cout << dp[n][1][1][1] << endl; return 0; } // Don't forget special cases. (n = 1?) // Look for the constraints. (Runtime array? overflow?)
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...