QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#57783 | #1277. Permutation | xukh | WA | 2ms | 3228kb | C++ | 1.6kb | 2022-10-22 21:38:41 | 2022-10-22 21:38:41 |
Judging History
answer
#include<stdio.h>
#include<algorithm>
#include<map>
using namespace std;
typedef unsigned long long ull;
map<ull,pair<long long,ull> > dp,tmp;
int n;
#define mod ((long long)(1e9)+7)
void fen(ull x){
printf("{");
for(int i=0;i<n;++i){
if(((x)>>i)&1){
printf("%d ",i);
}
}
printf("}");
}
bool check(ull x,ull fx,int add){
fx=~fx;
fx&=(1ULL<<n)-1;
if(add<=n/2){
fx>>=max(n-add*2-1,0);
}else{
x>>=max(add*2-n+1,0);
}
return (x&fx)==0;
}
void run(){
dp.clear();
tmp.clear();
dp[0].first=1,dp[0].second=0;
scanf("%d",&n);
ull jj=n;
for(int ww=0;ww!=n;++ww){
int x;
scanf("%d",&x);
if(x==0){
for(map<ull,pair<long long,ull> >::iterator it=dp.begin();it!=dp.end();++it){
for(x=0;x<n;++x){
if((it->first>>x)&1){
continue;
}
if(check(it->first,it->second.second,x)){
(tmp[it->first|(1<<x)].first+=it->second.first)%=mod,tmp[it->first|(1<<x)].second=it->second.second|(1<<(n-x-1));
}
}
}
}else{
jj--;
x--;
for(map<ull,pair<long long,ull> >::iterator it=dp.begin();it!=dp.end();++it){
if((it->first>>x)&1){
continue;
}
if(check(it->first,it->second.second,x)){
(tmp[it->first|(1<<x)].first+=it->second.first)%=mod,tmp[it->first|(1<<x)].second=it->second.second|(1<<(n-x-1));
}
}
}
dp=tmp;
tmp.clear();
}
ull jie=1;
for(ull i=1;i<=jj;++i){
jie=(jie*i)%mod;
}
printf("%lld\n",((long long)jie-(long long)dp[(1<<n)-1].first+mod)%mod);
}
int main(){
int t;
scanf("%d",&t);
while(t--){
run();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 3220kb
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: 3200kb
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: -100
Wrong Answer
time: 2ms
memory: 3228kb
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:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
result:
wrong answer 1st words differ - expected: '0', found: '1'