QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#210383#4843. Infectious Diseaseucup-team1004RE 1ms3460kbC++141.5kb2023-10-11 12:54:412023-10-11 12:54:45

Judging History

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

  • [2023-10-11 12:54:45]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3460kb
  • [2023-10-11 12:54:41]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<typename T>
ostream& operator << (ostream &out,const vector<T>&x){
	if(x.empty())return out<<"[]";
	out<<'['<<x[0];
	for(int len=x.size(),i=1;i<len;i++)out<<','<<x[i];
	return out<<']';
}
template<typename T>
vector<T> ary(const T *a,int l,int r){
	return vector<T>{a+l,a+1+r};
}
template<typename T>
void debug(T x){
	cerr<<x<<'\n';
}
template<typename T,typename ...S>
void debug(T x,S ...y){
	cerr<<x<<' ',debug(y...);
}
const int N=1.4e7+10,M=15,K=1<<M,mod=1e9+7;
int n,m,f[M][K];
int fac[K],ifac[K],pw[K];
ll qpow(ll x,ll y=mod-2){
	ll ans=1;
	for(;y;(x*=x)%=mod,y>>=1)if(y&1)(ans*=x)%=mod;
	return ans;
}
void init(){
	for(m=0,pw[0]=1;pw[m]*3<=n;m++)pw[m+1]=pw[m]*3;
	for(int i=fac[0]=1;i<=n;i++)fac[i]=1ll*fac[i-1]*i%mod;
	ifac[n]=qpow(fac[n]);
	for(int i=n;i>=1;i--)ifac[i-1]=1ll*ifac[i]*i%mod;
}
int C(int n,int m){
	if(0>m||m>n)return 0;
	return 1ll*fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}
int iC(int n,int m){
	if(0>m||m>n)return 0;
	return 1ll*ifac[n]*fac[m]%mod*fac[n-m]%mod;
}
int main(){
	cin>>n,init();
	f[0][1]=1;
	for(int i=0;i<m;i++){
		for(int j=1;j<=(1<<i);j++){
			if(!f[i][j])continue;
			int x=j,y=n-pw[i]-j,t=min(x,y);
			x+=t,y-=t;
			int z=pw[i]*2,l=max(0,z-y),r=min(x,z);
			for(int k=l;k<=r;k++){
				f[i+1][x-k]=(f[i+1][x-k]+1ll*f[i][j]*iC(x+y,z)%mod*C(x,k)%mod*C(y,z-k))%mod;
			}
		}
	}
	int ans=0;
	for(int i=0;i<=m;i++){
		for(int j=1;j<=(1<<i);j++){
			(ans+=f[i][j])%=mod;
		}
	}
	cout<<ans<<endl;
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3400kb

input:

2

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3460kb

input:

114

output:

505208013

result:

ok 1 number(s): "505208013"

Test #3:

score: -100
Runtime Error

input:

14000000

output:


result: