QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#408598#8339. Rooted TreeNelofus#TL 1148ms110296kbC++202.0kb2024-05-10 19:44:332024-05-10 19:44:34

Judging History

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

  • [2024-05-10 19:44:34]
  • 评测
  • 测评结果:TL
  • 用时:1148ms
  • 内存:110296kb
  • [2024-05-10 19:44:33]
  • 提交

answer

// Code by Heratino & Nelofus
// Narcissus & どうか安寧な記憶を

#include <bits/stdc++.h>
using i64 = long long;

//{{{誰にもなれない 私 胸張ってさ
template<typename Ta, typename Tb>
inline void chkmax(Ta &a, const Tb &b) {if (a < b)	a = b;}
template<typename Ta, typename Tb>
inline void chkmin(Ta &a, const Tb &b) {if (a > b)	a = b;}
char buf[1 << 20], *P1, *P2;
inline char gc() {
	if (P1 == P2)
		P2 = (P1 = buf) + fread(buf, 1, 1 << 20, stdin);
	return P1 == P2 ? EOF : *P1++;
}
template<typename T>
inline void read(T &ans) {
	ans = 0;
	T w = 1;
	char c = gc();
	while (!isdigit(c)) {
		if (c == '-')	w = -1;
		c = gc();
	}
	while (isdigit(c)) {
		ans = (ans << 3) + (ans << 1) + (c ^ 48);
		c = gc();
	}
	ans *= w;
}
template<typename T, typename ...Ts>
void read(T &a, Ts&... other) {
	read(a);
	read(other...);
}
//}}}

constexpr int mod = 1e9 + 9;
constexpr int N = 1e7 + 10;
inline int Plus(const int &x, const int &y) {return x + y >= mod ? x + y - mod : x + y;}
inline int Minu(const int &x, const int &y) {return x - y < 0 ? x - y + mod : x - y;}
inline int f_pow(int x, int k) {
	int base = 1;
	for (; k; k >>= 1, x = 1ll * x * x % mod)
		if (k & 1)
			base = 1ll * base * x % mod;
	return base;
}

int m, k;
int ifac[N];
int fac[N];
int ED[N];

inline int inv(int x) {
	return x ? 1ll * ifac[x] * fac[x - 1] % mod : 1;
}

int main() {
#ifdef HeratinoNelofus
	freopen("input.txt", "r", stdin);
#endif

	fac[0] = 1;
	for (int i = 1; i < N; i++)
		fac[i] = 1ll * fac[i - 1] * i % mod;
	ifac[N - 1] = f_pow(fac[N - 1], mod - 2);
	for (int i = N - 2; i >= 0; i--)
		ifac[i] = 1ll * ifac[i + 1] * (i + 1) % mod;

	read(m, k);

	ED[0] = 0;
	int ans = 0;
	for (int i = 1; i <= k; i++) {
		int pinv = f_pow(Plus(1ll * (i - 1) * (m - 1) % mod, 1), mod - 2);
		ans = Plus(ans, Plus(1ll * ED[i - 1] * pinv % mod, 1));
		ED[i] = 1ll * ED[i - 1] * (Plus(1ll * i * (m - 1) % mod, 1)) % mod * pinv % mod;
		ED[i] = Plus(ED[i], m);
	}
	std::cout << 1ll * m * ans % mod << '\n';
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 98ms
memory: 81720kb

input:

6 2

output:

18

result:

ok 1 number(s): "18"

Test #2:

score: 0
Accepted
time: 107ms
memory: 81768kb

input:

2 6

output:

600000038

result:

ok 1 number(s): "600000038"

Test #3:

score: 0
Accepted
time: 166ms
memory: 84112kb

input:

83 613210

output:

424200026

result:

ok 1 number(s): "424200026"

Test #4:

score: 0
Accepted
time: 1044ms
memory: 107800kb

input:

48 6713156

output:

198541581

result:

ok 1 number(s): "198541581"

Test #5:

score: 0
Accepted
time: 99ms
memory: 81728kb

input:

1 111

output:

6216

result:

ok 1 number(s): "6216"

Test #6:

score: 0
Accepted
time: 1148ms
memory: 110296kb

input:

28 7304152

output:

457266679

result:

ok 1 number(s): "457266679"

Test #7:

score: 0
Accepted
time: 678ms
memory: 97736kb

input:

38 4101162

output:

232117382

result:

ok 1 number(s): "232117382"

Test #8:

score: -100
Time Limit Exceeded

input:

51 9921154

output:

340670552

result: