QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#65756#4843. Infectious Diseaselqx123123WA 6ms11848kbC++141.5kb2022-12-03 16:33:072022-12-03 16:33:10

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-03 16:33:10]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:11848kb
  • [2022-12-03 16:33:07]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
const int N=14e6+6;

int n;
int jie[N],inv[N],top,pow3[20];
int dp[2][N];

bool v[N];
vector<int>id;

inline void add(int &x,int y){
	x+=y-(x+y>=mod?mod:0);
}

int ksm(int a,int b){
	int ans=1;
	while(b){
		if(b&1)ans=(1ll*ans*a)%mod;
		a=1ll*a*a%mod;
		b>>=1;
	}
	return ans;
}

void init(int lim){
	jie[0]=1;
	for(int i=1;i<=lim;i++)jie[i]=1ll*jie[i-1]*i%mod;
	inv[lim]=ksm(jie[lim],mod-2);
	for(int i=lim;i>=1;i--)inv[i-1]=1ll*inv[i]*i%mod;
	pow3[0]=1;
	while(pow3[top]<n)pow3[++top]=pow3[top-1]*3;
}

int C(int n,int m){
	return 1ll*jie[n]*inv[m]%mod*inv[n-m]%mod;
}

int invC(int n,int m){
	return 1ll*inv[n]*jie[m]%mod*jie[n-m]%mod;
}

int main(){
	scanf("%d",&n);
	init(n);
	int ans=0;
	dp[0][1]=1;
	for(int i=1;i<=top;i++){
		int p=i&1,q=p^1;
		int lim=min(n-pow3[i-1],2*pow3[i-1]);
		int inv_num=invC(n-pow3[i-1],lim);
		for(int j=1;j<=(1<<i-1)&&j<=n&&j+pow3[i-1]<=n;j++){
			int infected=min(n-pow3[i-1]-j,j);
			for(int k=0;k<=j+infected&&k<=lim;k++){
				int temp=1ll*C(j+infected,k)*C(n-pow3[i-1]-j-infected,lim-k)%mod;
				temp=(1ll*temp*inv_num)%mod;
				temp=(1ll*temp*dp[q][j])%mod;
				if(!v[j+infected-k]){
					dp[p][j+infected-k]=0;
					v[j+infected-k]=1;
					id.push_back(j+infected-k);
				}
				add(dp[p][j+infected-k],temp);
			}
		}
		for(auto x:id)v[x]=0;
		id.clear();
		add(ans,1ll*dp[p][0]*i%mod);
		//printf("%d:%d\n",i,3ll*dp[p][0]%mod);
	}
	printf("%d\n",ans);
	//printf("%d\n",5ll*ksm(3,mod-2)%mod);
}

詳細信息

Test #1:

score: 100
Accepted
time: 6ms
memory: 11816kb

input:

2

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: -100
Wrong Answer
time: 3ms
memory: 11848kb

input:

114

output:

106604856

result:

wrong answer 1st numbers differ - expected: '505208013', found: '106604856'