QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#726419 | #8339. Rooted Tree | beamishboys# | TL | 1391ms | 3716kb | C++23 | 744b | 2024-11-09 00:11:43 | 2024-11-09 00:11:44 |
Judging History
answer
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
const ll mod = 1e9+9;
ll modPow(ll n, ll p) {
ll b = n, o = 1;
while (p) {
if (p&1) o = (b*o)%mod;
p/=2;
b = (b*b)%mod;
}
return o;
}
ll inv(ll n) {
return modPow(n, mod-2);
}
int main() {
ll m, k; cin >> m >> k;
ll dleaf = 0, dnode = 0;
ll leafCnt = 1;
ll nodeCnt = 0;
for (ll i = 0; i < k; i++) {
dnode = nodeCnt*dnode + dleaf;
dnode %= mod;
dnode *= inv(nodeCnt+1);
dnode %= mod;
dleaf = (leafCnt+m-1)*dleaf + m;
dleaf %= mod;
leafCnt += m-1;
nodeCnt++;
dleaf *= inv(leafCnt);
dleaf %= mod;
}
ll out = dleaf*leafCnt + dnode * nodeCnt;
out %= mod;
cout << out << endl;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3512kb
input:
6 2
output:
18
result:
ok 1 number(s): "18"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
2 6
output:
600000038
result:
ok 1 number(s): "600000038"
Test #3:
score: 0
Accepted
time: 127ms
memory: 3644kb
input:
83 613210
output:
424200026
result:
ok 1 number(s): "424200026"
Test #4:
score: 0
Accepted
time: 1391ms
memory: 3552kb
input:
48 6713156
output:
198541581
result:
ok 1 number(s): "198541581"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3716kb
input:
1 111
output:
6216
result:
ok 1 number(s): "6216"
Test #6:
score: -100
Time Limit Exceeded
input:
28 7304152
output:
457266679