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 <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <deque>
#include <cassert>
using namespace std;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int N = 2e3 + 15;
int n, s, t, dp[N][N];
inline int add(int a, int b) {
a += b;
if(a >= mod)
a -= mod;
else if(a < 0)
a += mod;
return a;
}
inline void add_t(int &a, int b) {
a = add(a, b);
}
inline int mt(int a, int b) {
return 1ll * a * b % mod;
}
main() {
ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
// freopen("input.txt", "r", stdin);
cin >> n >> s >> t;
if(s > t)
swap(s, t);
dp[1][1] = 1;
for(int i = 2; i <= n; ++i) {
for(int j = 1; j <= n; ++j) {
if(i == s || i == t)
add_t(dp[i][j], add(dp[i-1][j-1], dp[i-1][j]));
else
add_t(dp[i][j], add(mt(dp[i-1][j+1], j), mt(dp[i-1][j-1], j - (i > s) - (i > t))));
}
}
cout << dp[n][1] << endl;
return 0;
}
Compilation message (stderr)
kangaroo.cpp:41:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main() {
^
# | 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... |