QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#57937#4843. Infectious DiseaseSorting#AC ✓737ms222604kbC++1.9kb2022-10-23 22:18:002022-10-23 22:18:06

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:18:06]
  • 评测
  • 测评结果:AC
  • 用时:737ms
  • 内存:222604kb
  • [2022-10-23 22:18:00]
  • 提交

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=16384;
typedef array<ll,16385> 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;
	int sz=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;
		sz*=2;
		for(int i=0; i<sz/2 ;i++) swap(cur[i],cur[sz-i]);
		for(int i=0; i<=iu ;i++){
			if(2*vac<i) base[i]=0;
			else base[i]=f[2*vac]*inf[i]%mod*inf[2*vac-i]%mod;//2*vac C i
		}
		{//cur=cur*base
			for(int i=sz; i>=0 ;i--){
				cur[i]=(cur[i]*base[0])%mod;
				for(int j=1; j<=i ;j++){
					cur[i]=(cur[i]+cur[i-j]*base[j])%mod;
				}
			}
		}
		for(int i=0; i<sz/2 ;i++) swap(cur[i],cur[sz-i]);
		//for(int i=0; i<16 ;i++) cout << base[i] << ' ';
		//cout << endl;
		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: 1ms
memory: 3660kb

input:

2

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 2ms
memory: 4040kb

input:

114

output:

505208013

result:

ok 1 number(s): "505208013"

Test #3:

score: 0
Accepted
time: 733ms
memory: 222604kb

input:

14000000

output:

44565093

result:

ok 1 number(s): "44565093"

Test #4:

score: 0
Accepted
time: 737ms
memory: 197044kb

input:

12345678

output:

123143093

result:

ok 1 number(s): "123143093"

Test #5:

score: 0
Accepted
time: 53ms
memory: 16196kb

input:

776777

output:

764022068

result:

ok 1 number(s): "764022068"

Test #6:

score: 0
Accepted
time: 2ms
memory: 3724kb

input:

3

output:

1

result:

ok 1 number(s): "1"

Test #7:

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

input:

4

output:

666666673

result:

ok 1 number(s): "666666673"

Test #8:

score: 0
Accepted
time: 2ms
memory: 3996kb

input:

5

output:

833333341

result:

ok 1 number(s): "833333341"

Test #9:

score: 0
Accepted
time: 2ms
memory: 3988kb

input:

6

output:

300000004

result:

ok 1 number(s): "300000004"

Test #10:

score: 0
Accepted
time: 2ms
memory: 3860kb

input:

7

output:

533333339

result:

ok 1 number(s): "533333339"

Test #11:

score: 0
Accepted
time: 1ms
memory: 3956kb

input:

8

output:

952380961

result:

ok 1 number(s): "952380961"

Test #12:

score: 0
Accepted
time: 2ms
memory: 4072kb

input:

9

output:

964285723

result:

ok 1 number(s): "964285723"

Test #13:

score: 0
Accepted
time: 3ms
memory: 4144kb

input:

10

output:

416666672

result:

ok 1 number(s): "416666672"

Test #14:

score: 0
Accepted
time: 1ms
memory: 3920kb

input:

26

output:

990086590

result:

ok 1 number(s): "990086590"

Test #15:

score: 0
Accepted
time: 2ms
memory: 4140kb

input:

27

output:

528360342

result:

ok 1 number(s): "528360342"

Test #16:

score: 0
Accepted
time: 2ms
memory: 3924kb

input:

28

output:

273239648

result:

ok 1 number(s): "273239648"

Test #17:

score: 0
Accepted
time: 189ms
memory: 78872kb

input:

4782967

output:

332194401

result:

ok 1 number(s): "332194401"

Test #18:

score: 0
Accepted
time: 192ms
memory: 78652kb

input:

4782968

output:

362625027

result:

ok 1 number(s): "362625027"

Test #19:

score: 0
Accepted
time: 188ms
memory: 78664kb

input:

4782969

output:

971032452

result:

ok 1 number(s): "971032452"

Test #20:

score: 0
Accepted
time: 661ms
memory: 78724kb

input:

4782970

output:

452836984

result:

ok 1 number(s): "452836984"

Test #21:

score: 0
Accepted
time: 670ms
memory: 78772kb

input:

4782971

output:

349324970

result:

ok 1 number(s): "349324970"

Test #22:

score: 0
Accepted
time: 668ms
memory: 78736kb

input:

4782972

output:

46862963

result:

ok 1 number(s): "46862963"

Test #23:

score: 0
Accepted
time: 2ms
memory: 5844kb

input:

114514

output:

972669965

result:

ok 1 number(s): "972669965"

Test #24:

score: 0
Accepted
time: 174ms
memory: 34092kb

input:

1919810

output:

482430785

result:

ok 1 number(s): "482430785"

Test #25:

score: 0
Accepted
time: 679ms
memory: 142712kb

input:

8877877

output:

486769120

result:

ok 1 number(s): "486769120"