제출 #869438

#제출 시각아이디문제언어결과실행 시간메모리
869438sleepntsheep캥거루 (CEOI16_kangaroo)C++17
0 / 100
0 ms348 KiB
#include <iostream> #include <cstring> #include <vector> #include <algorithm> #include <deque> #include <set> #include <utility> #include <array> #pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target("avx2,tune=native") using namespace std; #define ALL(x) x.begin(), x.end() #define ShinLena cin.tie(nullptr)->sync_with_stdio(false); using ll = long long; #define N 2005 const ll M = 1000000007; int n, cs, cf, dp[2][N][2][2]; int main() { ShinLena; cin >> n >> cs >> cf; dp[0][0][0][0] = 1; for (int I = 1, i = 1; i <= n; ++i, I ^= 1) { memset(dp[I], 0, sizeof *dp); if (i == cs) { for (int j = 1; j <= i; ++j) { dp[I][j][0][0] = 0; dp[I][j][1][0] = dp[!I][j][0][0] % M; dp[I][j][1][1] = (dp[!I][j-1][0][1] + dp[!I][j][0][1]) % M; } } if (i == cf) { for (int j = 1; j <= i; ++j) { dp[I][j][0][1] = (dp[!I][j-1][0][0] + dp[!I][j][0][0]) % M; dp[I][j][1][1] = (dp[!I][j-1][1][0] + dp[!I][j][1][0]) % M; } } else { for (int j = 1; j <= i; ++j) { dp[I][j][0][0] = ((1ll * dp[!I][j+1][0][0] * j) % M + (1ll * dp[!I][j-1][0][0] * (j+1) % M) ) % M; dp[I][j][1][0] = ( (1ll * dp[!I][j][0][0]) + (1ll * dp[!I][j+1][1][0] * j) % M ) % M; dp[I][j][0][1] = ( (1ll * dp[!I][j][0][0]) + (1ll * dp[!I][j+1][0][1] * j) % M ) % M; dp[I][j][1][1] = ( (1ll * dp[!I][j][0][1] + dp[!I][j][1][0]) % M + (1ll * dp[!I][j+1][1][1] * j) % M ) % M; } } } cout << dp[n&1][1][1][1]; 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...