QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#642580#1277. PermutationlyxWA 2ms10096kbC++141.6kb2024-10-15 15:04:032024-10-15 15:04:04

Judging History

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

  • [2024-10-15 15:04:04]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:10096kb
  • [2024-10-15 15:04:03]
  • 提交

answer

#include<bits/stdc++.h>
#define pb push_back
#define ls (g<<1)
#define rs (g<<1|1)
#define md (l+r>>1)
#define Ls l,md,ls
#define Rs md+1,r,rs
#define ll long long
#define rll register ll
#define ull unsigned ll
#define D double
#define rd register D
#define eps 1e-10
#define ri register int
#define fi first
#define se second
#define pii pair<int,int>
#define vi vector<int>
#define cr(x) memset(x,0,sizeof(x))
#define fo(i,x,y) for(ri i=(x);i<=(y);++i)
#define fu(i,x,y) for(ri i=(x);i<(y);++i)
#define fd(i,x,y) for(ri i=(x);i>=(y);--i)
using namespace std;
const int mo=2e6,K=mo+5;
const int N=55,p=1e9+7;
int n,a[N],be[N],st[K],ans=1;
struct Hash{
	int tt,hd[K],nt[K],f[K];ll to[K];
	inline void cl(){fo(i,1,tt)hd[to[i]%mo]=0;tt=0;}
	inline int hash(rll x,ri y){
		ri op=x%mo,s=1e9;
		for(ri i=hd[op];i;i=nt[i]){
			if(to[i]==x){s=(f[i]+=y)%=p;break;}
		}
		if(s==1e9){
			to[++tt]=x;nt[tt]=hd[op];hd[op]=tt;
			s=f[tt]=y;
		}
		return s;
	}
}H[2];
int main(){
	scanf("%d",&n);
	fo(i,1,n)scanf("%d",&a[i]);
	rll m=1ll<<n;
	H[0].hash(0,1);
	fo(i,1,n){
		ri s=(i-1)&1;
		fo(j,1,H[s].tt){
			rll x=H[s].to[j];ri t=0;
			fu(k,0,n)be[k]=0;
			fu(k,0,n)if(x>>k&1)st[++t]=k,be[k]=1;
			fu(k,0,n){
				if(x>>k&1)continue;
				if(a[i]&&k!=a[i])continue;
				ri pd=0;
				fo(l,1,t){
					ri u=k,v=st[l];
					if(u>v&&u+(u-v)<n&&!be[u+(u-v)]){pd=1;break;}
					if(u<v&&u-(v-u)>=0&&!be[u-(v-u)]){pd=1;break;}
				}
				if(!pd)H[s^1].hash(x|1ll<<k,H[s].f[j]);
			}
		}
		H[s].cl();
	}
	ri t=0;
	fo(i,1,n)if(!a[i])ans=1ll*ans*(++t)%p;
	ans=(ans-H[n&1].hash(m-1,0)+p)%p;
	printf("%d",ans);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 10096kb

input:

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

output:

1

result:

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