QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#642238#1277. PermutationchenyitaooooWA 0ms14032kbC++141.4kb2024-10-15 12:14:332024-10-15 12:14:34

Judging History

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

  • [2024-10-15 12:14:34]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:14032kb
  • [2024-10-15 12:14:33]
  • 提交

answer

#include<bits/stdc++.h>
#define Ri register int 
#define ci const int 
#define LL long long 
using namespace std;
const LL mo=1e9+7;
const int N=5e6+5;
int Q1[N],Q2[N],len1,len2,n,a[N],vis[N],TOT;
LL q1[N],q2[N];
unordered_map<LL,int>Q;
inline void upd(int &x,int y){
	x+=y;
	if(x>=mo) x-=mo;
}
void clr(){
	unordered_map<LL,int>VV;
	swap(VV,Q);
}
void Z(const LL o,const int f,const int i){
	for(Ri l=i-2,r=i; l>=0 && r<n; --l,++r){
		if(((o>>l)&1)!=((o>>r)&1)) return ;
	}
	LL OO=o|(1ll<<(i-1)),VV;
	if(Q[OO]==0) Q[OO]=++TOT,VV=TOT,q2[TOT]=OO,Q2[TOT]=0;
	else VV=Q[OO];
	upd(Q2[VV],f);
}
int main(){
//	freopen("permutation.in","r",stdin);
//	freopen("permutation.out","w",stdout);
	scanf("%d",&n);
	int ToT=0; 
	for(Ri i=1; i<=n; ++i){
		scanf("%d",&a[i]);
		if(a[i]>0) vis[a[i]]=1;
		else ++ToT; 
	}
	LL ans=1;
	for(Ri i=1; i<=ToT; ++i) ans=ans*i%mo;
	++len1;
	q1[1]=0,Q1[1]=1;
	for(Ri i=1; i<=n; ++i){
		TOT=0;
		clr();
		for(Ri j=1; j<=len1; ++j){
			const LL o=q1[j];
			ci f=Q1[j];
			if(a[i]>0) Z(o,f,a[i]);
			else{
				for(Ri j=1; j<=n; ++j){
					if((o>>(j-1))&1) continue;
					if(vis[j]==1) continue;
					Z(o,f,j);
				}
			}
		}
		len1=TOT;
		for(Ri j=1; j<=len1; ++j) q1[j]=q2[j],Q1[j]=Q2[j],q2[j]=Q2[j]=0;
//		printf("%d ",len1);
	}
	for(Ri i=1; i<=len1; ++i) ans=ans-Q1[i];
	printf("%lld\n",(ans%mo+mo)%mo);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 14032kb

input:

2
3
0 0 0
7
1 0 3 0 0 6 0

output:

1000000006

result:

wrong answer 1st words differ - expected: '2', found: '1000000006'