QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#375650 | #5532. Kangaroo | sichengzhou | 6 | 1ms | 4040kb | C++14 | 2.7kb | 2024-04-03 14:32:25 | 2024-04-03 14:32:26 |
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>=3)
{
f[i+1][j-1]+=((j-1)*(j-1)-(j-2)-1)%mod*f[i][j]%mod;
f[i+1][j-1]%=mod;
}else if(j==2&&i==n-1)
{
f[i+1][j-1]+=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: 3896kb
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: 30
Accepted
time: 1ms
memory: 4040kb
input:
39 36 32
output:
964903316
result:
ok 1 number(s): "964903316"
Test #3:
score: 0
Accepted
time: 0ms
memory: 4004kb
input:
26 1 26
output:
955348527
result:
ok 1 number(s): "955348527"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3976kb
input:
40 11 33
output:
695661890
result:
ok 1 number(s): "695661890"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3976kb
input:
39 39 38
output:
717149364
result:
ok 1 number(s): "717149364"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3988kb
input:
40 10 25
output:
912929610
result:
ok 1 number(s): "912929610"
Test #7:
score: -30
Wrong Answer
time: 0ms
memory: 4036kb
input:
37 25 23
output:
642085439
result:
wrong answer 1st numbers differ - expected: '250748685', found: '642085439'
Subtask #3:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%