WA 50pts 求调
查看原帖
WA 50pts 求调
572133
潘德理2010楼主2024/7/22 15:45

rt。

计算方式跟题解的一模一样。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll p=1e9+7;
ll n,a[2010],d[2010],c[26],res=1,g;
char s[2020];
ll qp(ll x,ll y){
	ll ans=1,base=x;
	while(y){
		if(y%2) ans=ans*base%p;
		base=base*base%p;
		y/=2;
	}
	return ans;
} 
int main(){
	scanf("%lld%s",&n,s+1);
	a[0]=1,d[0]=1;
	for(ll i=1;i<=n;i++){
		a[i]=ll(a[i-1])*i%p;
	}
	for(ll i=1;i<=n;i++){
		d[i]=qp(a[i],p-2);
	}
	for(ll i=0;i<26;i++){
		c[s[i]-'a']++;
	}
	for(ll i=0;i<26;i++){
		if(c[i]%2) g++;
	}
	if(g>=2){
		printf("%lld",a[n]);
		return 0;
	}
	g=1;
	for(ll i=0;i<26;i++){
		if(c[i]%2) g=c[i];
	}
	res=res*a[n/2]*g%p;
	for(ll i=0;i<26;i++){
		res=res*a[(c[i]/2)*2]%p;
		res=res*d[c[i]/2]%p;
	}
	res=(a[n]+p-res)%p;
	printf("%lld",res);
}
2024/7/22 15:45
加载中...