Submission #754818

#TimeUsernameProblemLanguageResultExecution timeMemory
754818dreamoonKangaroo (CEOI16_kangaroo)C++14
100 / 100
85 ms70904 KiB
#include <iostream> #include <vector> #define LL long long using namespace std; const int ST = 1; const int ED = 2; const int MAX_N = 2005; const int MOD = 1e9 + 7; void add(LL &x, LL v) { x = (x + v) % MOD; } LL dp[MAX_N][MAX_N][4]; int get(int x, int bit) { return (x & bit) != 0; } int main() { ios::sync_with_stdio(0); cin.tie(0); int N, cs, cf; cin >> N >> cs >> cf; dp[0][0][0] = 1; for(int i = 1; i <= N; i++) { for(int j = 0; j < i; j++) { for(int k = 0; k < 4; k++) { if(i == cs) { add(dp[i][j + 1][k | ST], dp[i - 1][j][k]); add(dp[i][j][k | ST], dp[i - 1][j][k] * (j - (get(k, ED) && i < N))); } else if(i == cf) { add(dp[i][j + 1][k | ED], dp[i - 1][j][k]); add(dp[i][j][k | ED], dp[i - 1][j][k] * (j - (get(k, ST) && i < N))); } else { add(dp[i][j + 1][k], dp[i - 1][j][k]); if(j) { if(i < N) { if(k == 0) { add(dp[i][j - 1][k], dp[i - 1][j][k] * j * (j - 1)); } else if(k < 3) { add(dp[i][j - 1][k], dp[i - 1][j][k] * (j - 1) * (j - 1)); } else { add(dp[i][j - 1][k], dp[i - 1][j][k] * (j - 1) * (j - 2)); } } else { add(dp[i][j - 1][k], dp[i - 1][j][k]); } } } } } } cout << dp[N][1][ST | ED] << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...