QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#634056#8339. Rooted Tree_fcy_#AC ✓1115ms238096kbC++141.2kb2024-10-12 16:38:282024-10-12 16:38:33

Judging History

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

  • [2024-10-12 16:38:33]
  • 评测
  • 测评结果:AC
  • 用时:1115ms
  • 内存:238096kb
  • [2024-10-12 16:38:28]
  • 提交

answer

#include<bits/stdc++.h>
#define fi first
#define se second
#define int long long
using namespace std;
template <typename T> void qmin(T &x,T y) { x=min(x,y); }
template <typename T> void qmax(T &x,T y) { x=max(x,y); }
typedef pair<int,int> pii;
const int mod=1e9+9;
const int maxn=1e7+10;
int inf=1e18;
int de=0;
int n,m,k;
int leafsum[maxn],leaf[maxn],sum[maxn];
int qpow(int x,int y)
{
	int ans=1,base=x;
	while(y)
	{
		if(y&1)
		{
			ans*=base;
			ans%=mod;
		}
		base*=base;
		base%=mod;
		y>>=1;
	}
	return ans;
}
int ny(int x)
{
	return qpow(x,mod-2);
}
int add(int x,int y){
    x+=y; x%=mod;
    return x;
}
int del(int x,int y){
    x-=y; x%=mod; x+=mod; x%=mod;
    return x;
}
int mul(int x,int y){
    x*=y; x%=mod;
    return x;
}
void solve(){
    cin>>m>>k;
    for(int i=1;i<=k;i++){
        leafsum[i]=add(del(leafsum[i-1],leaf[i-1]),mul(m,leaf[i-1]+1));
        leaf[i]=mul(leafsum[i],ny(1+(m-1)*i));
        sum[i]=add(sum[i-1],mul(leaf[i-1]+1,m));
    }
    cout<<sum[k]<<"\n";
}
signed main(){
    ios::sync_with_stdio(0); cin.tie(0);
    int TT;
    TT=1;
    //cin>>TT;
    while(TT--){
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3596kb

input:

6 2

output:

18

result:

ok 1 number(s): "18"

Test #2:

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

input:

2 6

output:

600000038

result:

ok 1 number(s): "600000038"

Test #3:

score: 0
Accepted
time: 69ms
memory: 23084kb

input:

83 613210

output:

424200026

result:

ok 1 number(s): "424200026"

Test #4:

score: 0
Accepted
time: 754ms
memory: 162392kb

input:

48 6713156

output:

198541581

result:

ok 1 number(s): "198541581"

Test #5:

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

input:

1 111

output:

6216

result:

ok 1 number(s): "6216"

Test #6:

score: 0
Accepted
time: 814ms
memory: 177200kb

input:

28 7304152

output:

457266679

result:

ok 1 number(s): "457266679"

Test #7:

score: 0
Accepted
time: 460ms
memory: 102920kb

input:

38 4101162

output:

232117382

result:

ok 1 number(s): "232117382"

Test #8:

score: 0
Accepted
time: 1102ms
memory: 236180kb

input:

51 9921154

output:

340670552

result:

ok 1 number(s): "340670552"

Test #9:

score: 0
Accepted
time: 194ms
memory: 49844kb

input:

79 1801157

output:

620550406

result:

ok 1 number(s): "620550406"

Test #10:

score: 0
Accepted
time: 612ms
memory: 132132kb

input:

22 5417157

output:

457449071

result:

ok 1 number(s): "457449071"

Test #11:

score: 0
Accepted
time: 357ms
memory: 82264kb

input:

25 3210162

output:

36368303

result:

ok 1 number(s): "36368303"

Test #12:

score: 0
Accepted
time: 320ms
memory: 76168kb

input:

67 2919160

output:

935195555

result:

ok 1 number(s): "935195555"

Test #13:

score: 0
Accepted
time: 976ms
memory: 209448kb

input:

77 8613163

output:

482832472

result:

ok 1 number(s): "482832472"

Test #14:

score: 0
Accepted
time: 1109ms
memory: 237968kb

input:

90 10000000

output:

275581651

result:

ok 1 number(s): "275581651"

Test #15:

score: 0
Accepted
time: 1115ms
memory: 238096kb

input:

99 9999999

output:

126087169

result:

ok 1 number(s): "126087169"

Test #16:

score: 0
Accepted
time: 1095ms
memory: 238040kb

input:

100 10000000

output:

451590067

result:

ok 1 number(s): "451590067"

Extra Test:

score: 0
Extra Test Passed