QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#88574#2573. Two Permutationss8194272AC ✓76ms12496kbC++141.9kb2023-03-16 15:50:012023-03-16 15:50:05

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-16 15:50:05]
  • 评测
  • 测评结果:AC
  • 用时:76ms
  • 内存:12496kb
  • [2023-03-16 15:50:01]
  • 提交

answer

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<bitset>
#include<random>
#include<cmath>
#include<ctime>
#include<queue>
#include<map>
#include<set>

#define fi first
#define se second
#define max Max
#define min Min
#define abs Abs
#define lc (x<<1)
#define rc (x<<1|1)
#define mid ((l+r)>>1)
#define pb(x) push_back(x)
#define lowbit(x) ((x)&(-(x)))
#define fan(x) ((((x)-1)^1)+1)
#define mp(x,y) make_pair(x,y)
#define clr(f,n) memset(f,0,sizeof(int)*(n))
#define cpy(f,g,n) memcpy(f,g,sizeof(int)*(n))
#define SZ(x) ((int)(x.size()))
#define INF 0x3f3f3f3f

using namespace std;

inline int read()
{
	int ans=0,f=1;
	char c=getchar();
	while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){ans=(ans<<1)+(ans<<3)+c-'0';c=getchar();}
	return ans*f;
}

inline void write(int x)
{
	if(x<0) putchar('-'),x=-x;
	if(x/10) write(x/10);
	putchar((char)(x%10)+'0');
}

template<typename T>inline T Abs(T a){return a>0?a:-a;};
template<typename T,typename TT>inline T Min(T a,TT b){return a<b?a:b;}
template<typename T,typename TT> inline T Max(T a,TT b){return a<b?b:a;}

const int N=105,mod=1e9+7;
int n,k,f[2][N][N*N];

signed main()
{
	n=read();k=read();
	int now=0;
	f[0][0][0]=1;
	for(int i=0;i<n;++i)
	{
		memset(f[now^1],0,sizeof(f[now^1]));
		for(int j=0;j<=i;++j)
			for(int p=0;p<=k;++p)
				if(f[now][j][p])
				{
					if(j+1<=i) f[now^1][j+2][p]=(f[now^1][j+2][p]+f[now][j][p]*1ll*(i-j)%mod*(i-j))%mod;
					if(p+n-i<=k&&n-2*i+j>0) f[now^1][j+1][p+n-i]=(f[now^1][j+1][p+n-i]+f[now][j][p]*1ll*(i-j)%mod*(n-2*i+j)*2)%mod;
					if(p+(n-i)*2<=k&&n-2*i+j-1>0) f[now^1][j][p+(n-i)*2]=(f[now^1][j][p+(n-i)*2]+f[now][j][p]*1ll*(n-2*i+j)%mod*(n-2*i+j-1))%mod;
					if(n-i*2+j>0) f[now^1][j+1][p+n-i]=(f[now^1][j+1][p+n-i]+f[now][j][p]*1ll*(n-i*2+j))%mod;
				}
		now^=1;
	}
	write(f[now][n][k]);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 12336kb

input:

2 4

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 4ms
memory: 12216kb

input:

3 7

output:

12

result:

ok 1 number(s): "12"

Test #3:

score: 0
Accepted
time: 1ms
memory: 12336kb

input:

4 10

output:

24

result:

ok 1 number(s): "24"

Test #4:

score: 0
Accepted
time: 2ms
memory: 12428kb

input:

4 14

output:

96

result:

ok 1 number(s): "96"

Test #5:

score: 0
Accepted
time: 1ms
memory: 12236kb

input:

5 10

output:

0

result:

ok 1 number(s): "0"

Test #6:

score: 0
Accepted
time: 1ms
memory: 12212kb

input:

5 15

output:

120

result:

ok 1 number(s): "120"

Test #7:

score: 0
Accepted
time: 1ms
memory: 12344kb

input:

5 21

output:

2400

result:

ok 1 number(s): "2400"

Test #8:

score: 0
Accepted
time: 4ms
memory: 12496kb

input:

6 21

output:

720

result:

ok 1 number(s): "720"

Test #9:

score: 0
Accepted
time: 8ms
memory: 12344kb

input:

6 30

output:

25920

result:

ok 1 number(s): "25920"

Test #10:

score: 0
Accepted
time: 2ms
memory: 12344kb

input:

6 27

output:

106560

result:

ok 1 number(s): "106560"

Test #11:

score: 0
Accepted
time: 3ms
memory: 12340kb

input:

20 300

output:

644873710

result:

ok 1 number(s): "644873710"

Test #12:

score: 0
Accepted
time: 3ms
memory: 12336kb

input:

20 139

output:

0

result:

ok 1 number(s): "0"

Test #13:

score: 0
Accepted
time: 4ms
memory: 12288kb

input:

30 470

output:

491424690

result:

ok 1 number(s): "491424690"

Test #14:

score: 0
Accepted
time: 10ms
memory: 12328kb

input:

30 500

output:

8436035

result:

ok 1 number(s): "8436035"

Test #15:

score: 0
Accepted
time: 13ms
memory: 12336kb

input:

40 1000

output:

617159088

result:

ok 1 number(s): "617159088"

Test #16:

score: 0
Accepted
time: 8ms
memory: 12236kb

input:

40 900

output:

729805907

result:

ok 1 number(s): "729805907"

Test #17:

score: 0
Accepted
time: 13ms
memory: 12340kb

input:

60 1830

output:

16340084

result:

ok 1 number(s): "16340084"

Test #18:

score: 0
Accepted
time: 17ms
memory: 12336kb

input:

60 2000

output:

832198921

result:

ok 1 number(s): "832198921"

Test #19:

score: 0
Accepted
time: 43ms
memory: 12288kb

input:

100 5050

output:

437918130

result:

ok 1 number(s): "437918130"

Test #20:

score: 0
Accepted
time: 25ms
memory: 12376kb

input:

100 700

output:

0

result:

ok 1 number(s): "0"

Test #21:

score: 0
Accepted
time: 76ms
memory: 12236kb

input:

100 10000

output:

0

result:

ok 1 number(s): "0"