제출 #591135

#제출 시각아이디문제언어결과실행 시간메모리
591135blueKangaroo (CEOI16_kangaroo)C++17
100 / 100
26 ms16004 KiB
#include <iostream> #include <vector> using namespace std; using ll = long long; const ll mod = 1'000'000'007LL; ll ad(ll a, ll b) { return (a+b)%mod; } ll mul(ll a, ll b) { return (a*b)%mod; } void selfadd(int& a, int b) { a = ad(a, b); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int N, cs, cf; cin >> N >> cs >> cf; if(cs > cf) swap(cs, cf); int DP[1+N][2+N]; for(int i = 0; i <= N; i++) for(int j = 0; j <= 1+N; j++) DP[i][j] = 0; DP[0][1] = 1; for(int i = 1; i <= N; i++) { for(int j = 0; j <= 1+i; j++) { if(i == cs || i == cf) { selfadd(DP[i][j], DP[i-1][j]); if(j+1 <= N+1) selfadd(DP[i][j], DP[i-1][j+1]); } else { if(j >= 1) selfadd(DP[i][j], mul(j-1, DP[i-1][j-1])); if(j+1 <= N+1 && j+1 - (i < cs) - (i < cf) >= 0) selfadd(DP[i][j], mul(j+1 - (i < cs) - (i < cf), DP[i-1][j+1])); } // cerr << i << ' ' << j << " : " << DP[i][j] << '\n'; } } cout << DP[N][0] << '\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...