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 <vector>
using namespace std;
using ll = long long;
const ll mod = 1'000'000'007LL;
ll ad(ll a, ll b)
{
return (a+b)%mod;
}
ll mul(ll a, ll b)
{
return (a*b)%mod;
}
void selfadd(int& a, int b)
{
a = ad(a, b);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N, cs, cf;
cin >> N >> cs >> cf;
if(cs > cf)
swap(cs, cf);
int DP[1+N][2+N];
DP[0][1] = 1;
for(int i = 1; i <= N; i++)
{
for(int j = 0; j <= 1+i; j++)
{
DP[i][j] = 0;
if(i == cs || i == cf)
{
selfadd(DP[i][j], DP[i-1][j]);
if(j+1 <= N+1)
selfadd(DP[i][j], DP[i-1][j+1]);
}
else
{
if(j >= 1)
selfadd(DP[i][j], mul(j-1, DP[i-1][j-1]));
if(j+1 <= N+1 && j+1 - (i < cs) - (i < cf) >= 0)
selfadd(DP[i][j], mul(j+1 - (i < cs) - (i < cf), DP[i-1][j+1]));
}
// cerr << i << ' ' << j << " : " << DP[i][j] << '\n';
}
}
cout << DP[N][0] << '\n';
}
# | 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... |