# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
575713 | hoainiem | Kangaroo (CEOI16_kangaroo) | C++14 | 8 ms | 16084 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>
//#pragma GCC target("popcnt")
#define fi first
#define se second
#define lc id<<1
#define rc id<<1^1
#define val f[i][j]
const int mod = 1e9 + 7;
double begintime, endtime;
using namespace std;
inline void CALC_TIME()
{
endtime = clock();
cout << "\nexecution time : " << (endtime - begintime + 1) / 1000 << " s";
}
void add(int &x, int y)
{
x += y;
if (x >= mod)
x -= mod;
}
int mul(int x, int y)
{
return 1LL * x * y % mod;
}
typedef pair<int, int> pii;
int n, cs, cf;
int f[2008][2008];
int dq(int i, int j)
{
if (val != -1)
return val;
if (i == n)
return val = (j == 1);
int res = 0;
if (i + 1 == cs || i + 1 == cf)
{
add(res, dq(i + 1, j));
add(res, dq(i + 1, j + 1));
return val = res;
}
if (j > 1)
add(res, mul(j - 1, dq(i + 1, j - 1)));
add(res, mul(j + 1 - (i + 1 > cs) - (i + 1 > cf), dq(i + 1, j + 1)));
return val = res;
}
int main()
{
begintime = clock();
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("file.inp", "r", stdin);
freopen("file.out", "w", stdout);
#endif
memset(f, -1, sizeof(f));
cin >> n >> cs >> cf;
cout << dq(0, 0);
return 0;
}
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... |