QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#57781#1277. PermutationxukhWA 2ms3252kbC++1.5kb2022-10-22 21:33:012022-10-22 21:33:04

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-22 21:33:04]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3252kb
  • [2022-10-22 21:33:01]
  • 提交

answer

#include<stdio.h>
#include<algorithm>
#include<map>
using namespace std;
typedef unsigned long long ull;
map<ull,pair<int,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<int,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<int,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",(jie-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: 3164kb

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

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

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'