QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#423961#8339. Rooted Treeushg8877TL 1413ms56488kbC++14714b2024-05-28 20:08:482024-05-28 20:08:48

Judging History

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

  • [2024-05-28 20:08:48]
  • 评测
  • 测评结果:TL
  • 用时:1413ms
  • 内存:56488kb
  • [2024-05-28 20:08:48]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MP make_pair
const int MOD=1e9+9;
const int MAXN=1e7+5;
ll ksm(ll a,int b){ll r=1;while(b){if(b&1)r=r*a%MOD;a=a*a%MOD,b>>=1;}return r;}
ll m,k,f[MAXN];
int main(){
	ios::sync_with_stdio(false);
	// freopen("Otomachi_Una.in","r",stdin);
	// freopen("Otomachi_Una.out","w",stdout);
	cerr<<"Running time: "<<1.*clock()/CLOCKS_PER_SEC<<'\n';
	cin>>m>>k;
	f[k]=1;
	ll ans=k*(m-1)+1;
	for(int i=k-1;i>=0;i--){
		f[i]=i*(m-1)*ksm(i*(m-1)+1,MOD-2)%MOD*f[i+1]+
		ksm(i*(m-1)+1,MOD-2)*(1+m*f[i+1]%MOD)%MOD;
		f[i]%=MOD;
		ans+=(1+m*f[i+1]%MOD);
	}
	ans%=MOD;ans-=m*k+1;
	ans=(ans%MOD+MOD)%MOD;
	cout<<ans<<'\n';
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

6 2

output:

18

result:

ok 1 number(s): "18"

Test #2:

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

input:

2 6

output:

600000038

result:

ok 1 number(s): "600000038"

Test #3:

score: 0
Accepted
time: 131ms
memory: 8800kb

input:

83 613210

output:

424200026

result:

ok 1 number(s): "424200026"

Test #4:

score: 0
Accepted
time: 1413ms
memory: 56488kb

input:

48 6713156

output:

198541581

result:

ok 1 number(s): "198541581"

Test #5:

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

input:

1 111

output:

6216

result:

ok 1 number(s): "6216"

Test #6:

score: -100
Time Limit Exceeded

input:

28 7304152

output:

457266679

result: