QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#143070 | #2573. Two Permutations | balpoint_pen | AC ✓ | 119ms | 20044kb | C++14 | 1.0kb | 2023-08-20 15:09:29 | 2023-08-20 15:09:32 |
Judging History
answer
/*
Author: YZB
Problem:
Time:
*/
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define rep(_i_,_l_,_r_) for(int _i_=_l_;_i_<=_r_;_i_++)
//#define FILE
using namespace std;
int dp[2][105][10005];
signed main(){
#ifdef FILE
freopen(".in","r",stdin);
freopen(".out","w",stdout);
#endif
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n,m;
cin>>n>>m;
dp[0][0][0]=1;
int p=0;
for(int i=1;i<=n;i++){
p^=1;
memset(dp[p],0,sizeof dp[p]);
for(int j=0;j<i;j++){
for(int k=0;k<=n*n;k++){
if(!dp[p^1][j][k])continue;
dp[p][j+1][k+i]+=dp[p^1][j][k]%mod;
dp[p][j+1][k+i]%=mod;
if(j+2<=n){
dp[p][j+2][k+i+i]+=dp[p^1][j][k]*(i-j-1)*(i-j-1)%mod;
dp[p][j+2][k+i+i]%=mod;
}
dp[p][j+1][k+i]+=dp[p^1][j][k]*(i-j-1)*2ll%mod;
dp[p][j+1][k+i]%=mod;
dp[p][j][k]+=dp[p^1][j][k];
dp[p][j][k]%=mod;
}
}
}
for(int i=1;i<=n;i++)dp[p][n][m]=dp[p][n][m]*i%mod;
cout<<dp[p][n][m]<<'\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 5ms
memory: 20008kb
input:
2 4
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 5ms
memory: 19824kb
input:
3 7
output:
12
result:
ok 1 number(s): "12"
Test #3:
score: 0
Accepted
time: 0ms
memory: 19824kb
input:
4 10
output:
24
result:
ok 1 number(s): "24"
Test #4:
score: 0
Accepted
time: 1ms
memory: 19884kb
input:
4 14
output:
96
result:
ok 1 number(s): "96"
Test #5:
score: 0
Accepted
time: 5ms
memory: 19876kb
input:
5 10
output:
0
result:
ok 1 number(s): "0"
Test #6:
score: 0
Accepted
time: 0ms
memory: 19868kb
input:
5 15
output:
120
result:
ok 1 number(s): "120"
Test #7:
score: 0
Accepted
time: 1ms
memory: 20044kb
input:
5 21
output:
2400
result:
ok 1 number(s): "2400"
Test #8:
score: 0
Accepted
time: 5ms
memory: 19892kb
input:
6 21
output:
720
result:
ok 1 number(s): "720"
Test #9:
score: 0
Accepted
time: 0ms
memory: 19856kb
input:
6 30
output:
25920
result:
ok 1 number(s): "25920"
Test #10:
score: 0
Accepted
time: 1ms
memory: 19784kb
input:
6 27
output:
106560
result:
ok 1 number(s): "106560"
Test #11:
score: 0
Accepted
time: 6ms
memory: 19940kb
input:
20 300
output:
644873710
result:
ok 1 number(s): "644873710"
Test #12:
score: 0
Accepted
time: 4ms
memory: 19828kb
input:
20 139
output:
0
result:
ok 1 number(s): "0"
Test #13:
score: 0
Accepted
time: 9ms
memory: 19888kb
input:
30 470
output:
491424690
result:
ok 1 number(s): "491424690"
Test #14:
score: 0
Accepted
time: 10ms
memory: 20044kb
input:
30 500
output:
8436035
result:
ok 1 number(s): "8436035"
Test #15:
score: 0
Accepted
time: 13ms
memory: 19992kb
input:
40 1000
output:
617159088
result:
ok 1 number(s): "617159088"
Test #16:
score: 0
Accepted
time: 13ms
memory: 20040kb
input:
40 900
output:
729805907
result:
ok 1 number(s): "729805907"
Test #17:
score: 0
Accepted
time: 31ms
memory: 19872kb
input:
60 1830
output:
16340084
result:
ok 1 number(s): "16340084"
Test #18:
score: 0
Accepted
time: 28ms
memory: 19880kb
input:
60 2000
output:
832198921
result:
ok 1 number(s): "832198921"
Test #19:
score: 0
Accepted
time: 113ms
memory: 19944kb
input:
100 5050
output:
437918130
result:
ok 1 number(s): "437918130"
Test #20:
score: 0
Accepted
time: 118ms
memory: 19884kb
input:
100 700
output:
0
result:
ok 1 number(s): "0"
Test #21:
score: 0
Accepted
time: 119ms
memory: 19984kb
input:
100 10000
output:
0
result:
ok 1 number(s): "0"