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>
using namespace std;
#define X first
#define Y second
#define pb push_back
#define mp make_pair
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector< ii > vii;
typedef long long L;
typedef vector< L > vL;
typedef vector< vL > vvL;
typedef vector< vi > vvi;
typedef vector< vii > vvii;
const int inf = 1e9;
const L inf8 = 1e18;
const int md = 1e9 + 7;
int s, e;
int dp[2005][2005];
void add(int &a, int b)
{
a += b;
if(a>= md) a -= md;
}
int mul(int a, int b)
{
return (1LL*a*b)%md;
}
int cc(int i, int j)
{
if(i>= s) j--;
if(i>= e) j--;
return j;
}
int main()
{
int n; scanf("%d %d %d", &n, &s, &e);
dp[0][0] = 1;
int ans = 0;
for(int i = 1; i<= n; i++)
{
for(int j = 0; j<= n; j++)
{
int v = dp[i-1][j];
int f = cc(i-1, j);
if(i == s)
{
add(dp[i][j], mul(f, v));
add(dp[i][j+1], v);
if(i == n && j == 1) add(ans, v);
}
else if(i == e)
{
add(dp[i][j], mul(f, v));
add(dp[i][j+1], v);
if(i == n && j == 1) add(ans, v);
}
else
{
add(dp[i][j+1], v);
if(j && i-1>= s) add(dp[i][j-1], mul(f, v));
if(j && i-1>= e) add(dp[i][j-1], mul(f, v));
if(j) add(dp[i][j-1], mul(f, mul(f-1, v)));
if(i == n && j == 2) add(ans, v);
}
}
}
printf("%d\n", ans);
return 0;
}
Compilation message (stderr)
kangaroo.cpp: In function 'int main()':
kangaroo.cpp:37:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int n; scanf("%d %d %d", &n, &s, &e);
^
# | 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... |