Submission #519501

#TimeUsernameProblemLanguageResultExecution timeMemory
519501SamboorKangaroo (CEOI16_kangaroo)C++17
100 / 100
32 ms31820 KiB
// Grzegorz Ryn // V LO Kraków #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<bool> vb; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; #define pb push_back #define eb emplace_back #define mp make_pair #define mt make_tuple #define st first #define nd second #define FOR(__VAR, __START, __END) for(int __VAR=__START; __VAR<=__END; __VAR++) #define FORB(__VAR, __START, __END) for(int __VAR=__START; __VAR>=__END; __VAR--) #define FORK(__VAR, __START, __END, __DIFF) for(int __VAR=__START; __VAR<=END; __VAR+=__DIFF) #define all(__VAR) (__VAR).begin(), (__VAR).end() #define rall(__VAR) (__VAR).rbegin(), (__VAR).rend() #define DEBUG(__VAR) cout << #__VAR << ": " << __VAR << endl; template<typename __T1, typename __T2> ostream & operator<<(ostream &out, pair<__T1, __T2> &__VAR) { cout << "[" << __VAR.st << ", " << __VAR.nd << "]"; return out; } template<typename __T> ostream & operator<<(ostream &out, vector<__T> &__VAR) { cout << "["; FOR(i, 0, (int)__VAR.size()-2) cout << __VAR[i] << ", "; if(__VAR.size()>0) cout << __VAR[__VAR.size()-1]; cout << "]" << endl; return out; } const ll INF = 1e17, MOD = 1'000'000'000 + 7; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int N, b, e; cin >> N >> b >> e; vector<vector<ll>> dp(N+1, vector<ll>(N+1)); dp[1][1] = 1; for(ll i=2; i<=N; i++) { for(ll j=1; j<=N; j++) { if(i == b || i == e) { dp[i][j] = (dp[i-1][j-1] + dp[i-1][j]) % MOD; continue; } dp[i][j] = (j*dp[i-1][j+1]) % MOD; ll pos = j; if(b < i) { pos--; } if(e < i) { pos--; } dp[i][j] += dp[i-1][j-1] * pos; dp[i][j] %= MOD; } } 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...