#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%I64d", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%I64d\n", (n))
#define pii pair<int, int>
#define pil pair<int, long long>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vil vector<pil>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<ll,int,hash<ll>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int MOD2 = 1e9 + 9;
const int INF = 1e9 + 7;
const int MAXN = 2e3 + 5;
const double eps = 1e-9;
int n, cs, cf;
ll dp[MAXN][MAXN];
ll solve(int x, int y) {
dp[n+1][0] = 1;
int fl = 0;
for (int i = n; i > 0; i--) {
for (int j = 1; j <= n - i + 1; j++) {
if (i == cs)
dp[i][j] = dp[i+1][j-x];
else if (i == cf)
dp[i][j] = dp[i+1][j-y];
else
dp[i][j] = (dp[i+1][j-1] * 1ll * (ll) (j - fl) + dp[i+1][j+1] * 1ll * (ll) j) % MOD;
}
if (i == cs || i == cf)
fl++;
}
return dp[1][1];
}
int main() {
scanf("%d %d %d", &n, &cs, &cf);
ll ans = (solve(0, (n+1)&1) + solve(1, n&1)) % MOD;
printf("%lld\n", ans);
return 0;
}
Compilation message
kangaroo.cpp: In function 'int main()':
kangaroo.cpp:60:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d", &n, &cs, &cf);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
2 ms |
504 KB |
Output is correct |
6 |
Correct |
2 ms |
504 KB |
Output is correct |
7 |
Correct |
2 ms |
504 KB |
Output is correct |
8 |
Correct |
2 ms |
508 KB |
Output is correct |
9 |
Correct |
2 ms |
504 KB |
Output is correct |
10 |
Correct |
2 ms |
504 KB |
Output is correct |
11 |
Correct |
2 ms |
632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
2 ms |
504 KB |
Output is correct |
6 |
Correct |
2 ms |
504 KB |
Output is correct |
7 |
Correct |
2 ms |
504 KB |
Output is correct |
8 |
Correct |
2 ms |
508 KB |
Output is correct |
9 |
Correct |
2 ms |
504 KB |
Output is correct |
10 |
Correct |
2 ms |
504 KB |
Output is correct |
11 |
Correct |
2 ms |
632 KB |
Output is correct |
12 |
Correct |
3 ms |
1272 KB |
Output is correct |
13 |
Correct |
3 ms |
1144 KB |
Output is correct |
14 |
Correct |
3 ms |
1272 KB |
Output is correct |
15 |
Correct |
3 ms |
1272 KB |
Output is correct |
16 |
Correct |
3 ms |
1272 KB |
Output is correct |
17 |
Correct |
3 ms |
1276 KB |
Output is correct |
18 |
Correct |
3 ms |
1144 KB |
Output is correct |
19 |
Correct |
3 ms |
1272 KB |
Output is correct |
20 |
Correct |
3 ms |
1272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
2 ms |
504 KB |
Output is correct |
6 |
Correct |
2 ms |
504 KB |
Output is correct |
7 |
Correct |
2 ms |
504 KB |
Output is correct |
8 |
Correct |
2 ms |
508 KB |
Output is correct |
9 |
Correct |
2 ms |
504 KB |
Output is correct |
10 |
Correct |
2 ms |
504 KB |
Output is correct |
11 |
Correct |
2 ms |
632 KB |
Output is correct |
12 |
Correct |
3 ms |
1272 KB |
Output is correct |
13 |
Correct |
3 ms |
1144 KB |
Output is correct |
14 |
Correct |
3 ms |
1272 KB |
Output is correct |
15 |
Correct |
3 ms |
1272 KB |
Output is correct |
16 |
Correct |
3 ms |
1272 KB |
Output is correct |
17 |
Correct |
3 ms |
1276 KB |
Output is correct |
18 |
Correct |
3 ms |
1144 KB |
Output is correct |
19 |
Correct |
3 ms |
1272 KB |
Output is correct |
20 |
Correct |
3 ms |
1272 KB |
Output is correct |
21 |
Correct |
6 ms |
4728 KB |
Output is correct |
22 |
Correct |
7 ms |
5112 KB |
Output is correct |
23 |
Correct |
7 ms |
5556 KB |
Output is correct |
24 |
Correct |
28 ms |
23032 KB |
Output is correct |
25 |
Correct |
33 ms |
23032 KB |
Output is correct |
26 |
Correct |
32 ms |
23032 KB |
Output is correct |
27 |
Correct |
28 ms |
22796 KB |
Output is correct |
28 |
Correct |
18 ms |
15096 KB |
Output is correct |