QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#375633 | #5532. Kangaroo | sichengzhou | 6 | 1ms | 4032kb | C++14 | 2.6kb | 2024-04-03 14:23:45 | 2024-04-03 14:23:46 |
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=2020,mod=1e9+7;
int n,cs,cf;
LL f[N][N];
int main()
{
scanf("%d%d%d",&n,&cs,&cf);
f[0][0]=1;
for(int i=0;i<n;i++)
{
for(int j=0;j<=i;j++)
{
if(i+1==cs)
{
if(cf<=i)
{
if(j>=2)
{
f[i+1][j]+=f[i][j]*(j-1)%mod;
f[i+1][j]%=mod;
}else if(j==1)
{
f[i+1][j]+=f[i][j]*j%mod;
f[i+1][j]%=mod;
}
}else{
if(j>=1)
{
f[i+1][j]+=f[i][j]*j%mod;
f[i+1][j]%=mod;
}
}
}else if(i+1==cf)
{
if(cs<=i)
{
if(j>=2)
{
f[i+1][j]+=f[i][j]*(j-1)%mod;
f[i+1][j]%=mod;
}else if(j==1)
{
f[i+1][j]+=f[i][j]*j%mod;
f[i+1][j]%=mod;
}
}else{
if(j>=1)
{
f[i+1][j]+=f[i][j]*j%mod;
f[i+1][j]%=mod;
}
}
}else{
if(i<cs&&i<cf)
{
if(j>=2)
{
f[i+1][j-1]+=j*(j-1)%mod*f[i][j]%mod;
f[i+1][j-1]%=mod;
}
}else if(cs<=i&&cf<=i)
{
if(j>=2)
{
f[i+1][j-1]+=((j-1)*(j-1)-(j-2))%mod*f[i][j]%mod;
f[i+1][j-1]%=mod;
}
}else if(cs<=i)
{
if(j>=2)
{
f[i+1][j-1]+=(j*(j-1)-(j-1))%mod*f[i][j]%mod;
f[i+1][j-1]%=mod;
}
}else{
if(j>=2)
{
f[i+1][j-1]+=(j*(j-1)-(j-1))%mod*f[i][j]%mod;
f[i+1][j-1]%=mod;
}
}
}
f[i+1][j+1]+=f[i][j];
f[i+1][j+1]%=mod;
}
}
printf("%lld\n",f[n][1]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 6
Accepted
Test #1:
score: 6
Accepted
time: 0ms
memory: 3984kb
input:
7 3 6
output:
14
result:
ok 1 number(s): "14"
Subtask #2:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Test #2:
score: 0
Wrong Answer
time: 1ms
memory: 4032kb
input:
39 36 32
output:
145708195
result:
wrong answer 1st numbers differ - expected: '964903316', found: '145708195'
Subtask #3:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%