# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
741043 | Bogdan1110 | Kangaroo (CEOI16_kangaroo) | C++14 | 1 ms | 468 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define FAST {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
#define FILES {freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);}
#define ll long long
#define ull unsigned long long
#define pqueue priority_queue
#define pb push_back
#define fi first
#define se second
#define ld long double
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) (a).begin(), (a).end()
#define mp make_pair
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key -> # less than k
// find_by_order -> k-th element
// pq max element
void files() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
const double eps = 0.00000001;
const int NMAX = 2020;
const ll inf = LLONG_MAX/3;
const ll modi = 1e9+7;
int s,t;
int calc[NMAX][NMAX];
int memo[NMAX][NMAX];
ll dp(int i, int j){
if ( j > i ) return 0;
if ( i == 1 ) {
if ( j == 1 ) {
return 1;
}
return 0;
}
if ( calc[i][j] ) {
return memo[i][j];
}
if ( i == s || i == t ) {
memo[i][j] = dp(i-1,j-1) + dp(i-1,j);
memo[i][j] %= modi;
}
else {
memo[i][j] = dp(i-1,j-1) * (j-(i>s)-(i>t));
memo[i][j] %= modi;
memo[i][j] += dp(i-1,j+1) * (j);
memo[i][j] %= modi;
}
calc[i][j] = 1;
return memo[i][j];
}
void solve() {
int n;
cin >> n;
cin >> s >> t;
cout << dp(n,1);
}
int main () {
FAST
int t=1;
/*
cin >> t;
//*/
int i = 1;
while(t--) {
//cout << "Case #" << i++ << ": " ;
solve();
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |