QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#90725#1277. PermutationS00021TL 943ms76360kbC++143.2kb2023-03-24 23:54:102023-03-24 23:54:14

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-24 23:54:14]
  • 评测
  • 测评结果:TL
  • 用时:943ms
  • 内存:76360kb
  • [2023-03-24 23:54:10]
  • 提交

answer

#include<bits/stdc++.h>
#define int __int128
#define N 55
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define M 1000000007
using namespace std;
int n,cn,T,vs[N],p[N];
int rev(int n) {
    n = (n & 0xaaaaaaaa) >> 1 | (n & 0x55555555) << 1;
    n = (n & 0xcccccccc) >> 2 | (n & 0x33333333) << 2;
    n = (n & 0xf0f0f0f0) >> 4 | (n & 0x0f0f0f0f) << 4;
    n = (n & 0xff00ff00) >> 8 | (n & 0x00ff00ff) << 8;
    n = (n & 0xffff0000) >> 16 | (n & 0x0000ffff) << 16;
    return n >> 32 | n << 32;
}namespace io {
	const int __SIZE = (1 << 21) + 1;
	char ibuf[__SIZE], *iS, *iT, obuf[__SIZE], *oS = obuf, *oT = oS + __SIZE - 1, __c, qu[55]; int __f, qr, _eof;
	#define Gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	inline void flush () { fwrite (obuf, 1, oS - obuf, stdout), oS = obuf; }
	inline void gc (char &x) { x = Gc(); }
	inline void pc (char x) { *oS ++ = x; if (oS == oT) flush (); }
	inline void pstr (const char *s) { int __len = strlen(s); for (__f = 0; __f < __len; ++__f) pc (s[__f]); }
	inline void gstr (char *s) { for(__c = Gc(); __c < 32 || __c > 126 || __c == ' ';)  __c = Gc();
		for(; __c > 31 && __c < 127 && __c != ' ' && __c != '\n' && __c != '\r'; ++s, __c = Gc()) *s = __c; *s = 0; }
	template <class I> inline bool gi (I &x) { _eof = 0;
		for (__f = 1, __c = Gc(); (__c < '0' || __c > '9') && !_eof; __c = Gc()) { if (__c == '-') __f = -1; _eof |= __c == EOF; }
		for (x = 0; __c <= '9' && __c >= '0' && !_eof; __c = Gc()) x = x * 10 + (__c & 15), _eof |= __c == EOF; x *= __f; return !_eof; }
	template <class I> inline void print (I x) { if (!x) pc ('0'); if (x < 0) pc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10; while (qr) pc (qu[qr --]); }
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
} using io::pc; using io::gc; using io::pstr; using io::gstr; using io::gi; using io::print;
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};  map<int,int>f;
void inc(int &x,int y){x+=y; if(x>=M) x-=M;}
int clc(int S,int l,int r){return (S&((1ll<<(r+1))-1))>>l;}
bool chk(int S,int i){
	if(S>>i&1) return 0; int va=min(i,n-i-1);
	return clc(S,i-va,i-1)==(rev(clc(S,i+1,i+va))>>(64-va));
}void slv(){
	int cn=0; gi(n); f.clear(),memset(vs,0,sizeof(vs)),f[0]=1; 
	for(int i=0;i<n;i++) gi(p[i]),(~(--p[i]))&&(vs[p[i]]=1),cn+=(p[i]==-1);
	for(auto u:f){
		int va=p[__builtin_popcountll((long long)u.fi)];
		if(va!=-1) {if(u.se&&chk(u.fi,va)) inc(f[u.fi^(1ll<<va)],u.se);}
		else for(int t=0;t<n;t++) if(!vs[t]&&u.se&&chk(u.fi,t)) inc(f[u.fi^(1ll<<t)],u.se);
	}int mul=1;
	for(int i=cn;i;i--) mul=mul*i%M; print((mul+M-f[(1ll<<n)-1])%M),pc('\n');
}signed main(){
	gi(T); while(T--) slv();
	return 0;
}

詳細信息

Test #1:

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

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: 2ms
memory: 3392kb

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: 2ms
memory: 3348kb

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: 2ms
memory: 3436kb

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: 0ms
memory: 3332kb

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: 2ms
memory: 3396kb

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: 2ms
memory: 3332kb

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

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

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: 2ms
memory: 3268kb

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

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: 4ms
memory: 4068kb

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

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: 141ms
memory: 18332kb

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: 134ms
memory: 13548kb

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: 2ms
memory: 3320kb

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: 2ms
memory: 3404kb

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: 943ms
memory: 76360kb

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: 651ms
memory: 55780kb

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: 248ms
memory: 26236kb

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: 75ms
memory: 12028kb

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: 26ms
memory: 6484kb

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: 3ms
memory: 4144kb

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: 2ms
memory: 3388kb

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

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: 2ms
memory: 3312kb

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

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

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: 2ms
memory: 3320kb

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: 0ms
memory: 3400kb

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: