제출 #788616

#제출 시각아이디문제언어결과실행 시간메모리
788616WLZ캥거루 (CEOI16_kangaroo)C++17
100 / 100
26 ms16060 KiB
#include <bits/stdc++.h> using namespace std; const int MOD = (int) 1e9 + 7; /** Assumes 1 <= a, b < MOD */ int add(int a, int b) { if (a + b >= MOD) return a + b - MOD; return a + b; } /** Assumes 1 <= a, b < MOD */ int sub(int a, int b) { return add(a, MOD - b); } /** Assumes 1 <= a, b < MOD */ int mul(int a, int b) { return (long long) a * b % MOD; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, cs, cf; cin >> n >> cs >> cf; vector< vector<int> > dp(n + 1, vector<int>(n + 1, 0)); dp[0][0] = 1; for (int i = 1; i <= n; i++) { for (int j = 1; j < n; j++) { if (i == cs || i == cf) { dp[i][j] = add(dp[i - 1][j], dp[i - 1][j - 1]); } else { dp[i][j] = add(mul(dp[i - 1][j - 1], j - (i > cs) - (i > cf)), mul(dp[i - 1][j + 1], j)); } } } 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...