QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#57931#4843. Infectious DiseaseSorting#WA 554ms222648kbC++1.5kb2022-10-23 22:05:142022-10-23 22:05:15

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-23 22:05:15]
  • 评测
  • 测评结果:WA
  • 用时:554ms
  • 内存:222648kb
  • [2022-10-23 22:05:14]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
const ll mod=1e9+7;
const int iu=4096;
typedef array<ll,4097> arin;
ll n;
arin operator* (arin x,arin y){
	arin z;
	for(int i=0; i<=iu ;i++) z[i]=0;
	for(int i=0; i<=iu ;i++){
		for(int j=0; i+j<=iu ;j++){
			z[i+j]=(z[i+j]+x[i]*y[j])%mod;
		}
	}
	return z;
}
arin one,base,cur;
arin pw(arin x,ll y){
	if(y==0) return one;
	if(y%2==1) return x*pw(x,y-1);
	auto res=pw(x,y/2);
	return res*res;
}
const int N=1.4e7+1;
ll f[N],inf[N];
ll pw(ll x,ll y){
	if(y==0) return 1;
	if(y%2) return x*pw(x,y-1)%mod;
	ll res=pw(x,y/2);
	return res*res%mod;
}
void pre(){
	f[0]=1;
	for(int i=1; i<=n ;i++) f[i]=f[i-1]*i%mod;
	inf[n]=pw(f[n],mod-2);
	for(int i=n; i>=1 ;i--) inf[i-1]=inf[i]*i%mod;
	one[0]=1;base[0]=1;base[1]=2;base[2]=1;
	cur[1]=inf[n-1]*f[n-2]%mod;
	
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);
	cin >> n;
	pre();
	ll pb=1;
	ll ans=1;
	for(int vac=1; vac*3<n ;vac*=3){
		arin nc;
		for(int j=0; j<=iu ;j++) nc[j]=0;
		for(int i=iu/2; i>=1 ;i--){
			if(cur[i]==0 || n-vac-2*i<0) continue;
			nc[i*2]=cur[i]*inf[i]%mod*inf[n-vac-i]%mod*f[2*i]%mod*f[n-vac-2*i]%mod;
			//cout << i*2 << ' ' << nc[i*2] << endl;
		}
		cur=nc;
		for(int i=0; i<iu/2 ;i++) swap(cur[i],cur[iu-i]);
		cur=cur*base;base=(base*base)*base;
		for(int i=0; i<iu/2 ;i++) swap(cur[i],cur[iu-i]);
		ll ways=cur[0];
		
		//cout << "win " << ways << endl;
		pb=(pb+mod-ways)%mod;
		ans=(ans+pb)%mod;
	}
	cout << ans << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3664kb

input:

2

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 115ms
memory: 3708kb

input:

114

output:

505208013

result:

ok 1 number(s): "505208013"

Test #3:

score: -100
Wrong Answer
time: 554ms
memory: 222648kb

input:

14000000

output:

483040186

result:

wrong answer 1st numbers differ - expected: '44565093', found: '483040186'