QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#602501 | #1277. Permutation | rollerZ | WA | 182ms | 5608kb | C++23 | 1.7kb | 2024-10-01 09:00:11 | 2024-10-01 09:00:11 |
Judging History
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<ll,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,int>().swap(f[0]),f[0][0]=1;
rep(i,1,n){
cur^=1;
gp_hash_table<ll,int>().swap(f[cur]);
for(pair<ll,int>p:f[cur^1]){
int S=p.fi,v=p.se;
rep(j,a[i]?a[i]:0,a[i]?a[i]:n-1)if(!(S>>j&1)){
bool flag=1;
rep(k,0,n-1){
if(!(S>>k&1)&&(S>>(j+j-k)&1)){
flag=0;
break;
}
}
if(flag)(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: 0ms
memory: 3792kb
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: 3728kb
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: 3716kb
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: 3664kb
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: 3732kb
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: 4092kb
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: 3808kb
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: 3756kb
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: 3672kb
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: 3828kb
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: 18ms
memory: 4128kb
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: 3ms
memory: 3892kb
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: 32ms
memory: 4044kb
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: 182ms
memory: 5608kb
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: 109ms
memory: 4372kb
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: -100
Wrong Answer
time: 1ms
memory: 3732kb
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 708 362821
result:
wrong answer 4th words differ - expected: '718', found: '708'