QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#57785 | #1277. Permutation | xukh | WA | 3ms | 3312kb | C++ | 1.6kb | 2022-10-22 21:40:25 | 2022-10-22 21:40:25 |
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);
if(n<=2){
printf("0\n");
return;
}
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: 3ms
memory: 3308kb
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: 3096kb
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: 3220kb
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: 3168kb
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: -100
Wrong Answer
time: 2ms
memory: 3312kb
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:
3628639 3628639 3628639 3628639 3628639
result:
wrong answer 1st words differ - expected: '3627734', found: '3628639'