QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#726419#8339. Rooted Treebeamishboys#TL 1391ms3716kbC++23744b2024-11-09 00:11:432024-11-09 00:11:44

Judging History

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

  • [2024-11-09 00:11:44]
  • 评测
  • 测评结果:TL
  • 用时:1391ms
  • 内存:3716kb
  • [2024-11-09 00:11:43]
  • 提交

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

result: