QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#883701 | #8339. Rooted Tree | arashMLG# | AC ✓ | 354ms | 160060kb | C++20 | 1.8kb | 2025-02-05 18:14:18 | 2025-02-05 18:14:23 |
Judging History
answer
#include<bits/stdc++.h>
#ifdef LOCAL
#include "Essentials/algo/debug.h"
#else
#define debug(...) 69
#define debugArr(...) 69
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int N = 5e5 + 23;
const ll inf = 1e18;
#define F first
#define S second
#define pb push_back
#define kill(x) cout<<x<<endl, exit(0);
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define lc (v << 1)
#define rc ((v<<1) |1)
const int mod = 1e9+9;
ll pw(ll a , ll b , ll md = mod) {
ll ans = 1;
while(b) {
if(b&1)
ans = ans * a % md;
b >>= 1;
a = a * a % md;
}
return ans;
}
const int K = 1e7+2;
int fac[K];
int inv[K];
int dp[K], ways[K];
int m , k;
int32_t main() {
cin.tie(nullptr)->sync_with_stdio(false);
fac[0] = 1;
for(int i = 1 ; i < K ; i ++)
fac[i] = 1ll * fac[i-1] * i % mod;
inv[K-1] = pw(fac[K-1] , mod-2);
for(int i = K-1 ; i ; i --)
inv[i-1] = 1ll * inv[i] * i % mod;
cin >> m >> k;
ways[1] = 1;
for(int i=2; i<K; i++) ways[i] = (1+ll(i-1)*(m-1))%mod;
for(int i=k-1; i>=1; i--) ways[i] = 1ll*ways[i]*ways[i+1]%mod;
dp[1] = 1;
ll sum = 1+1;
ll cur = 1;
for(int i = 2 ; i <= k ; i ++) {
dp[i] = 1ll * m * sum % mod * fac[i-2] % mod;
sum = 1ll * sum * (m-1) % mod;
cur = cur * (1 + 1ll*(i-1)*(m-1)%mod) % mod;
sum = (sum + 1ll * (dp[i] + cur) * inv[i-1] % mod) % mod;
}
ll ans = 0;
for(int i = 1 ; i <= k ; i ++)
(ans += 1ll * dp[i] * (i==k ? 1 : ways[i+1])%mod * m % mod) %= mod;
cout << 1ll*ans*pw(ways[1], mod-2)%mod << endl;
return 0;
}
// Jumpsuit, Jumpsuit cover me!
// Jumpsuit, Jumpsuit cover me!
详细
Test #1:
score: 100
Accepted
time: 103ms
memory: 123192kb
input:
6 2
output:
18
result:
ok 1 number(s): "18"
Test #2:
score: 0
Accepted
time: 102ms
memory: 123196kb
input:
2 6
output:
600000038
result:
ok 1 number(s): "600000038"
Test #3:
score: 0
Accepted
time: 111ms
memory: 125240kb
input:
83 613210
output:
424200026
result:
ok 1 number(s): "424200026"
Test #4:
score: 0
Accepted
time: 255ms
memory: 149692kb
input:
48 6713156
output:
198541581
result:
ok 1 number(s): "198541581"
Test #5:
score: 0
Accepted
time: 101ms
memory: 123192kb
input:
1 111
output:
6216
result:
ok 1 number(s): "6216"
Test #6:
score: 0
Accepted
time: 281ms
memory: 151864kb
input:
28 7304152
output:
457266679
result:
ok 1 number(s): "457266679"
Test #7:
score: 0
Accepted
time: 202ms
memory: 139452kb
input:
38 4101162
output:
232117382
result:
ok 1 number(s): "232117382"
Test #8:
score: 0
Accepted
time: 350ms
memory: 159928kb
input:
51 9921154
output:
340670552
result:
ok 1 number(s): "340670552"
Test #9:
score: 0
Accepted
time: 141ms
memory: 131384kb
input:
79 1801157
output:
620550406
result:
ok 1 number(s): "620550406"
Test #10:
score: 0
Accepted
time: 239ms
memory: 145588kb
input:
22 5417157
output:
457449071
result:
ok 1 number(s): "457449071"
Test #11:
score: 0
Accepted
time: 179ms
memory: 135476kb
input:
25 3210162
output:
36368303
result:
ok 1 number(s): "36368303"
Test #12:
score: 0
Accepted
time: 178ms
memory: 133432kb
input:
67 2919160
output:
935195555
result:
ok 1 number(s): "935195555"
Test #13:
score: 0
Accepted
time: 320ms
memory: 157884kb
input:
77 8613163
output:
482832472
result:
ok 1 number(s): "482832472"
Test #14:
score: 0
Accepted
time: 347ms
memory: 160060kb
input:
90 10000000
output:
275581651
result:
ok 1 number(s): "275581651"
Test #15:
score: 0
Accepted
time: 354ms
memory: 160044kb
input:
99 9999999
output:
126087169
result:
ok 1 number(s): "126087169"
Test #16:
score: 0
Accepted
time: 353ms
memory: 159928kb
input:
100 10000000
output:
451590067
result:
ok 1 number(s): "451590067"
Extra Test:
score: 0
Extra Test Passed