QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#217112#1277. PermutationCrysflyTL 1082ms21048kbC++172.9kb2023-10-16 15:05:142023-10-16 15:05:14

Judging History

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

  • [2023-10-16 15:05:14]
  • 评测
  • 测评结果:TL
  • 用时:1082ms
  • 内存:21048kb
  • [2023-10-16 15:05:14]
  • 提交

answer

// what is matter? never mind. 
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2") 
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
#define ull unsigned long long
//#define int __int128
#define int long long
using namespace std;
inline int read()
{
	char c=getchar();int x=0;bool f=0;
	for(;!isdigit(c);c=getchar())f^=!(c^45);
	for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
	if(f)x=-x;return x;
}

#define mod 1000000007
struct modint{
	int x;
	modint(int o=0){x=o;}
	modint &operator = (int o){return x=o,*this;}
	modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
	modint &operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;}
	modint &operator *=(modint o){return x=1ll*x*o.x%mod,*this;}
	modint &operator ^=(int b){
		modint a=*this,c=1;
		for(;b;b>>=1,a*=a)if(b&1)c*=a;
		return x=c.x,*this;
	}
	modint &operator /=(modint o){return *this *=o^=mod-2;}
	friend modint operator +(modint a,modint b){return a+=b;}
	friend modint operator -(modint a,modint b){return a-=b;}
	friend modint operator *(modint a,modint b){return a*=b;}
	friend modint operator /(modint a,modint b){return a/=b;}
	friend modint operator ^(modint a,int b){return a^=b;}
	friend bool operator ==(modint a,int b){return a.x==b;}
	friend bool operator !=(modint a,int b){return a.x!=b;}
	bool operator ! () {return !x;}
	modint operator - () {return x?mod-x:0;}
	bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,int y){return x^y;}

vector<modint> fac,ifac,iv;
inline void initC(int n)
{
	if(iv.empty())fac=ifac=iv=vector<modint>(2,1);
	int m=iv.size(); ++n;
	if(m>=n)return;
	iv.resize(n),fac.resize(n),ifac.resize(n);
	For(i,m,n-1){
		iv[i]=iv[mod%i]*(mod-mod/i);
		fac[i]=fac[i-1]*i,ifac[i]=ifac[i-1]*iv[i];
	}
}
inline modint C(int n,int m){
	if(m<0||n<m)return 0;
	return initC(n),fac[n]*ifac[m]*ifac[n-m];
}
inline modint sign(int n){return (n&1)?(mod-1):(1);}

#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;

#define maxn 2000005
#define inf 0x3f3f3f3f

int n,res,p[maxn];
map<int,modint>f,g;

int chk(int s,int x){
	if(s>>x&1)return 0;
	For(i,1,n)
		if((s>>i&1)){
			int y=2*x-i;
			if(y>=1 && y<=n && !(s>>y&1))return 0;
		}
	return 1;
}

void work()
{
	n=read();
	int qwq=0;
	For(i,1,n)p[i]=read(),qwq+=!p[i];
	f.clear();
	f[0]=1;
	For(i,1,n){
		g.clear();
		for(auto [s,w]:f){
			For(j,1,n)
				if((j==p[i]||!p[i]) && chk(s,j)) g[s|(1ll<<j)]+=f[s];
		}
		swap(f,g);
	}
	auto [s,w]=*f.begin();
	modint sum=1;
	For(i,1,qwq)sum*=i;
	w=sum-w;
	cout<<w.x<<"\n";
}

signed main()
{
	int T=read();
	while(T--)work();
	return 0;
}
/*
4 10 20 48 104 282
4 2 
18 14 4
*/

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3576kb

input:

2
3
0 0 0
7
1 0 3 0 0 6 0

output:

2
21

result:

ok 2 tokens

Test #2:

score: 0
Accepted
time: 0ms
memory: 3648kb

input:

50
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

result:

ok 50 tokens

Test #3:

score: 0
Accepted
time: 0ms
memory: 3724kb

input:

25
2
0 0
2
0 0
2
0 0
2
0 0
2
0 0
2
0 0
2
0 0
2
0 0
2
0 0
2
0 0
2
0 0
2
0 0
2
0 0
2
0 0
2
0 0
2
0 0
2
0 0
2
0 0
2
0 0
2
0 0
2
0 0
2
0 0
2
0 0
2
0 0
2
0 0

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

result:

ok 25 tokens

Test #4:

score: 0
Accepted
time: 0ms
memory: 3640kb

input:

16
3
0 0 0
3
0 0 0
3
0 0 0
3
0 0 0
3
0 0 0
3
0 0 0
3
0 0 0
3
0 0 0
3
0 0 0
3
0 0 0
3
0 0 0
3
0 0 0
3
0 0 0
3
0 0 0
3
0 0 0
3
0 0 0

output:

2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2

result:

ok 16 tokens

Test #5:

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

input:

5
10
0 0 0 0 0 0 0 0 0 0
10
0 0 0 0 0 0 0 0 0 0
10
0 0 0 0 0 0 0 0 0 0
10
0 0 0 0 0 0 0 0 0 0
10
0 0 0 0 0 0 0 0 0 0

output:

3627734
3627734
3627734
3627734
3627734

result:

ok 5 tokens

Test #6:

score: 0
Accepted
time: 0ms
memory: 3644kb

input:

4
11
0 10 11 6 1 0 8 0 0 3 5
11
0 0 0 10 8 5 4 1 0 2 9
11
0 4 0 3 11 0 0 0 7 8 1
11
0 8 0 3 9 0 0 0 7 4 0

output:

24
24
120
720

result:

ok 4 tokens

Test #7:

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

input:

4
12
0 0 11 0 0 6 1 0 4 0 5 8
12
7 0 10 11 4 6 1 8 0 12 0 0
12
0 12 0 0 0 0 5 0 1 0 10 11
12
0 0 4 3 9 12 2 5 1 10 6 0

output:

720
24
5040
6

result:

ok 4 tokens

Test #8:

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

input:

3
13
0 13 6 3 0 11 0 0 0 0 1 2 0
13
9 0 0 0 0 0 8 0 5 7 0 12 0
13
0 0 0 0 0 0 3 10 2 9 0 12 0

output:

5040
40320
40320

result:

ok 3 tokens

Test #9:

score: 0
Accepted
time: 0ms
memory: 3580kb

input:

3
14
0 12 10 9 0 0 11 0 0 1 6 4 8 13
14
0 0 8 0 0 9 14 3 0 0 6 2 0 0
14
13 0 8 0 0 0 0 0 14 7 4 6 0 3

output:

120
40320
5040

result:

ok 3 tokens

Test #10:

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

input:

3
15
8 7 12 14 6 0 0 9 4 0 1 0 0 0 2
15
5 0 0 9 0 7 15 0 13 4 11 0 0 0 2
15
0 0 0 2 0 0 7 0 0 8 0 13 14 10 3

output:

720
5040
40320

result:

ok 3 tokens

Test #11:

score: 0
Accepted
time: 12ms
memory: 3860kb

input:

2
20
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
20
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

output:

143388927
143388927

result:

ok 2 tokens

Test #12:

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

input:

1
30
21 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

output:

586750519

result:

ok "586750519"

Test #13:

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

input:

1
40
0 0 0 0 23 26 0 0 0 0 0 0 32 20 33 0 0 0 0 0 0 0 0 0 0 0 0 0 36 0 0 0 0 0 0 0 0 0 0 0

output:

943272305

result:

ok "943272305"

Test #14:

score: 0
Accepted
time: 450ms
memory: 18632kb

input:

1
41
0 0 0 0 0 0 0 0 0 14 38 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 15 0 0 35 9 0 0

output:

523095984

result:

ok "523095984"

Test #15:

score: 0
Accepted
time: 875ms
memory: 21048kb

input:

1
42
0 0 0 0 0 0 0 0 0 0 0 0 4 22 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 38 0 0 0 1 0

output:

472948359

result:

ok "472948359"

Test #16:

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

input:

5
10
0 0 7 0 0 0 0 0 0 3
10
0 5 0 0 0 0 0 9 0 0
10
1 6 0 0 0 0 0 5 0 0
10
0 0 4 0 0 0 3 0 1 9
10
0 0 0 0 0 0 0 6 0 0

output:

40320
40320
5040
718
362648

result:

ok 5 tokens

Test #17:

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

input:

5
9
0 6 0 0 0 0 0 0 0
9
6 0 0 0 3 0 0 7 0
9
8 0 0 0 0 0 7 3 4
9
0 0 0 0 0 0 0 0 0
9
0 0 0 0 0 0 8 2 0

output:

40270
720
120
362384
4996

result:

ok 5 tokens

Test #18:

score: 0
Accepted
time: 1082ms
memory: 20988kb

input:

1
42
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

output:

94131117

result:

ok "94131117"

Test #19:

score: 0
Accepted
time: 738ms
memory: 16232kb

input:

1
40
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

output:

614960773

result:

ok "614960773"

Test #20:

score: 0
Accepted
time: 285ms
memory: 11136kb

input:

1
35
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

output:

478043548

result:

ok "478043548"

Test #21:

score: 0
Accepted
time: 90ms
memory: 5740kb

input:

1
30
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

output:

343955582

result:

ok "343955582"

Test #22:

score: 0
Accepted
time: 27ms
memory: 4320kb

input:

1
25
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

output:

242322220

result:

ok "242322220"

Test #23:

score: 0
Accepted
time: 6ms
memory: 3852kb

input:

1
20
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

output:

143388927

result:

ok "143388927"

Test #24:

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

input:

5
10
0 0 0 2 0 9 0 5 0 0
10
0 1 0 3 7 0 0 0 0 0
10
0 0 10 8 0 0 0 9 0 7
10
0 7 1 9 0 0 0 0 0 0
10
0 4 0 0 10 0 0 0 9 0

output:

5028
5000
719
5018
5034

result:

ok 5 tokens

Test #25:

score: 0
Accepted
time: 0ms
memory: 3592kb

input:

5
10
5 1 9 7 3 0 4 10 2 6
10
5 9 1 3 7 6 2 0 4 8
10
6 2 10 4 8 1 9 5 3 0
10
0 10 6 4 8 5 9 1 7 3
10
8 4 10 2 6 5 9 1 0 3

output:

0
0
0
0
0

result:

ok 5 tokens

Test #26:

score: 0
Accepted
time: 0ms
memory: 3588kb

input:

5
10
0 3 0 0 5 10 2 6 4 8
10
5 1 0 3 7 0 4 2 10 6
10
0 3 9 1 5 6 0 10 0 4
10
0 3 5 9 1 6 10 0 8 4
10
5 1 9 7 3 0 4 6 2 0

output:

4
1
5
1
1

result:

ok 5 tokens

Test #27:

score: 0
Accepted
time: 0ms
memory: 3640kb

input:

1
42
29 13 21 37 5 17 33 1 0 0 41 11 27 35 3 19 31 15 23 39 7 12 28 4 36 20 24 0 0 32 16 2 34 18 26 10 42 0 30 6 38 22

output:

118

result:

ok "118"

Test #28:

score: 0
Accepted
time: 0ms
memory: 3704kb

input:

1
42
37 5 21 13 29 17 1 33 25 9 41 3 35 0 0 27 23 0 7 31 15 32 16 8 40 24 0 0 20 28 0 30 0 0 38 22 10 0 0 0 0 18

output:

479001592

result:

ok "479001592"

Test #29:

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

input:

1
42
0 29 0 0 21 33 1 17 41 9 0 15 31 0 7 23 0 0 0 0 35 20 4 36 28 12 32 0 0 40 24 26 10 0 18 34 0 0 38 6 0 0

output:

789741538

result:

ok "789741538"

Test #30:

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

input:

1
42
0 0 25 0 1 33 0 0 0 29 0 0 0 35 0 0 7 39 0 31 0 0 42 0 0 0 2 0 38 22 14 0 0 0 0 0 28 24 0 0 0 0

output:

394131909

result:

ok "394131909"

Test #31:

score: -100
Time Limit Exceeded

input:

1
50
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

output:


result: