QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#602520#1277. PermutationrollerZTL 154ms4436kbC++231.6kb2024-10-01 10:10:112024-10-01 10:10:11

Judging History

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

  • [2024-10-01 10:10:11]
  • 评测
  • 测评结果:TL
  • 用时:154ms
  • 内存:4436kb
  • [2024-10-01 10:10:11]
  • 提交

answer

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <ctime>
#include <random>
#include <cassert>
#include <numeric>
#include <cmath>
#include <ext/pb_ds/assoc_container.hpp>
#define pii pair<int, int>
#define fi first
#define se second
#define MP make_pair
#define ep emplace
#define eb emplace_back
#define int long long
#define rep(i, j, k) for (int i = (j); i <= (k); i++)
#define per(i, j, k) for (int i = (j); i >= (k); i--)
typedef double db;
typedef long double ldb;
typedef long long ll;
//typedef __int128 lll;
typedef unsigned long long ull;
typedef unsigned int ui;
using namespace __gnu_pbds;
using namespace std;

int read() {
	int s = 0, f = 1;
	char c = getchar();
	while (c < '0' || c > '9') f ^= (c == '-'), c = getchar();
	while (c >= '0' && c <= '9') s = s * 10 + c - '0', c = getchar();
	return f ? s : -s;
}

const int N=55,mod=1e9+7;
int n,a[N];
gp_hash_table<int,int>f[2];

signed main() {
	for(int T=read();T--;){
		n=read();
		int cnt=0,mul=1;
		rep(i,1,n)a[i]=read();
		rep(i,1,n)if(!a[i])cnt++;
		rep(i,1,cnt)(mul*=i)%=mod;
		int cur=0;
		gp_hash_table<ll,ll>().swap(f[0]),f[0][0]=1;
		rep(i,1,n){
			cur^=1;
			gp_hash_table<ll,ll>().swap(f[cur]);
			for(pii p:f[cur^1]){
				int S=p.fi,v=p.se,SS=(1ll<<n)-1;
				rep(j,0,n-1)SS^=(S>>j&1)<<(n-j-1);
				rep(j,a[i]?a[i]-1:0,a[i]?a[i]-1:n-1)if(!(S>>j&1)){
					if(!(S&(n-j-j-1>=0?(SS>>(n-j-j-1)):(SS<<(j+j+1-n)))))(f[cur][S^(1ll<<j)]+=v)%=mod;
				}
			}
		}
		printf("%lld\n",(mul-f[cur][(1ll<<n)-1]+mod)%mod);
	}
	return 0;
}

詳細信息

Test #1:

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

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: 1ms
memory: 3736kb

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: 1ms
memory: 3740kb

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: 3996kb

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: 3816kb

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: 1ms
memory: 3732kb

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: 3720kb

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: 3776kb

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: 1ms
memory: 3784kb

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: 3708kb

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: 10ms
memory: 3928kb

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: 6ms
memory: 3856kb

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: 154ms
memory: 4436kb

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: -100
Time Limit Exceeded

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:


result: