QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#602513 | #1277. Permutation | rollerZ | WA | 0ms | 3712kb | C++23 | 1.6kb | 2024-10-01 09:48:00 | 2024-10-01 09:48:01 |
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<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&(SS>>(j+j-n+1))))(f[cur][S^(1ll<<j)]+=v)%=mod;
}
}
}
printf("%lld\n",(mul-f[cur][(1ll<<n)-1]+mod)%mod);
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3712kb
input:
2 3 0 0 0 7 1 0 3 0 0 6 0
output:
2 24
result:
wrong answer 2nd words differ - expected: '21', found: '24'