QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#372372 | #8339. Rooted Tree | zzuqy# | AC ✓ | 109ms | 121108kb | C++14 | 901b | 2024-03-31 12:16:05 | 2024-03-31 12:16:05 |
Judging History
answer
#include <bits/stdc++.h>
#define fep(A,B,C) for(int C=A;C>=B;--C)
#define rep(A,B,C) for(int C=A;C<=B;++C)
#define ll long long
using namespace std;
const int MAXN=10000010;
#define mod 1000000009
int n,k,m;
int f[MAXN],g[MAXN];
int w[MAXN];
int ksm(int b,int p)
{
int cnt=1;
while(p)
{
if(p&1)cnt=(ll)cnt*b%mod;
b=(ll)b*b%mod;p=p>>1;
}
return cnt;
}
int main()
{
//freopen("1.in","r",stdin);
scanf("%d%d",&m,&k);
w[k+1]=1;
fep(k,0,i)
{
w[i]=(ll)((m-1)*i+1)*w[i+1]%mod;
}
int cc=ksm(w[0],mod-2);
f[0]=0;g[0]=0;
//f为叶子节点的深度期望
//g为所有节点总期望
rep(1,k,i)
{
int sz=(i-1)*m+1;
int yz=sz-i+1;
int nex=yz+m-1;
f[i]=(f[i-1]+(ll)m*cc%mod*w[i+1])%mod;
g[i]=(g[i-1]+(ll)m*(f[i-1]+1))%mod;
cc=(ll)cc*((m-1)*i+1)%mod;
//cout<<f[i]<<' '<<g[i]<<endl;
}
printf("%d\n",g[k]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7888kb
input:
6 2
output:
18
result:
ok 1 number(s): "18"
Test #2:
score: 0
Accepted
time: 1ms
memory: 7944kb
input:
2 6
output:
600000038
result:
ok 1 number(s): "600000038"
Test #3:
score: 0
Accepted
time: 9ms
memory: 15488kb
input:
83 613210
output:
424200026
result:
ok 1 number(s): "424200026"
Test #4:
score: 0
Accepted
time: 55ms
memory: 87496kb
input:
48 6713156
output:
198541581
result:
ok 1 number(s): "198541581"
Test #5:
score: 0
Accepted
time: 1ms
memory: 7968kb
input:
1 111
output:
6216
result:
ok 1 number(s): "6216"
Test #6:
score: 0
Accepted
time: 62ms
memory: 95016kb
input:
28 7304152
output:
457266679
result:
ok 1 number(s): "457266679"
Test #7:
score: 0
Accepted
time: 34ms
memory: 58360kb
input:
38 4101162
output:
232117382
result:
ok 1 number(s): "232117382"
Test #8:
score: 0
Accepted
time: 100ms
memory: 120664kb
input:
51 9921154
output:
340670552
result:
ok 1 number(s): "340670552"
Test #9:
score: 0
Accepted
time: 20ms
memory: 27740kb
input:
79 1801157
output:
620550406
result:
ok 1 number(s): "620550406"
Test #10:
score: 0
Accepted
time: 54ms
memory: 70552kb
input:
22 5417157
output:
457449071
result:
ok 1 number(s): "457449071"
Test #11:
score: 0
Accepted
time: 42ms
memory: 47184kb
input:
25 3210162
output:
36368303
result:
ok 1 number(s): "36368303"
Test #12:
score: 0
Accepted
time: 30ms
memory: 45860kb
input:
67 2919160
output:
935195555
result:
ok 1 number(s): "935195555"
Test #13:
score: 0
Accepted
time: 109ms
memory: 111228kb
input:
77 8613163
output:
482832472
result:
ok 1 number(s): "482832472"
Test #14:
score: 0
Accepted
time: 77ms
memory: 120976kb
input:
90 10000000
output:
275581651
result:
ok 1 number(s): "275581651"
Test #15:
score: 0
Accepted
time: 88ms
memory: 121108kb
input:
99 9999999
output:
126087169
result:
ok 1 number(s): "126087169"
Test #16:
score: 0
Accepted
time: 102ms
memory: 120988kb
input:
100 10000000
output:
451590067
result:
ok 1 number(s): "451590067"
Extra Test:
score: 0
Extra Test Passed