Submission #587231

#TimeUsernameProblemLanguageResultExecution timeMemory
587231Jarif_RahmanKangaroo (CEOI16_kangaroo)C++17
100 / 100
31 ms31712 KiB
#include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; const ll md = 1e9+7; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n, s, e; cin >> n >> s >> e; s--, e--; vector<vector<ll>> dp(n, vector<ll>(n+1, 0)); dp[0][1] = 1; for(int i = 1; i < n; i++) for(int j = 1; j <= i+1; j++) { int c = 0; c+=(s < i); c+=(e < i); if(j > 1) dp[i][j]+=dp[i-1][j-1], dp[i][j]%=md; if(i == s || i == e){ if(c == 0) dp[i][j]+=(dp[i-1][j]*j)%md, dp[i][j]%=md; else if(i == n-1 && j == 1) dp[i][j]+=dp[i-1][j], dp[i][j]%=md; else if(j != 1) dp[i][j]+=(dp[i-1][j]*(j-1))%md, dp[i][j]%=md; } else if(j+1 <= i){ if(c == 0) dp[i][j]+=(dp[i-1][j+1]*j*(j+1))%md, dp[i][j]%=md; else if(c == 1) dp[i][j]+=(dp[i-1][j+1]*j*j)%md, dp[i][j]%=md; else if(i == n-1 && j == 1) dp[i][j]+=dp[i-1][j+1], dp[i][j]%=md; else if(j != 1) dp[i][j]+=(dp[i-1][j+1]*j*(j-1))%md, dp[i][j]%=md; } } cout << dp[n-1][1] << "\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...