QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#883593 | #8339. Rooted Tree | amirali_asgari# | AC ✓ | 148ms | 238172kb | C++20 | 1.6kb | 2025-02-05 17:08:39 | 2025-02-05 17:08:48 |
Judging History
answer
// In the name of Allah
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef complex<ld> cld;
#define all(x) (x).begin(),(x).end()
#define len(x) ((ll) (x).size())
#define F first
#define S second
#define pb push_back
#define sep ' '
#define endl '\n'
#define Mp make_pair
#define kill(x) cout << x << '\n', exit(0)
#define set_dec(x) cout << fixed << setprecision(x);
#define file_io(x,y) freopen(x, "r", stdin); freopen(y, "w", stdout);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 1e7 + 4;
const int mod = 1e9 + 9;
int m, k;
ll dp[maxn], valk[maxn], valR[maxn];
ll power(ll a, ll b) {
if (b == 0) return 1;
return power(a * a % mod, b / 2) * ((b & 1) ? a : 1) % mod;
}
void solve() {
cin >> m >> k;
ll ans = 0; dp[0] = 0;
valk[0] = 1; valR[k + 1] = 1;
for (int i = 1; i <= k; i++) {
ll sz = 1 + (m - 1) * (i - 1);
valk[i] = valk[i - 1] * sz % mod;
}
for (int i = k; i >= 1; i--) {
ll sz = 1 + (m - 1) * (i - 1);
valR[i] = valR[i + 1] * sz % mod;
}
for (int i = 1; i <= k; i++) {
ll sz = 1 + (m - 1) * (i - 1);
ll valx = (dp[i - 1] + valk[i]) * m % mod;
ans += valx * valR[i + 1]; ans %= mod;
dp[i] = ((dp[i - 1] * sz) + valk[i] + ((dp[i - 1] + valk[i]) * (m - 1))) % mod;
}
(ans *= power(valk[k], mod - 2)) %= mod;
cout << ans << endl;
}
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int T = 1;
while (T--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 7920kb
input:
6 2
output:
18
result:
ok 1 number(s): "18"
Test #2:
score: 0
Accepted
time: 0ms
memory: 7788kb
input:
2 6
output:
600000038
result:
ok 1 number(s): "600000038"
Test #3:
score: 0
Accepted
time: 5ms
memory: 21472kb
input:
83 613210
output:
424200026
result:
ok 1 number(s): "424200026"
Test #4:
score: 0
Accepted
time: 96ms
memory: 166056kb
input:
48 6713156
output:
198541581
result:
ok 1 number(s): "198541581"
Test #5:
score: 0
Accepted
time: 0ms
memory: 7920kb
input:
1 111
output:
6216
result:
ok 1 number(s): "6216"
Test #6:
score: 0
Accepted
time: 99ms
memory: 178256kb
input:
28 7304152
output:
457266679
result:
ok 1 number(s): "457266679"
Test #7:
score: 0
Accepted
time: 62ms
memory: 104516kb
input:
38 4101162
output:
232117382
result:
ok 1 number(s): "232117382"
Test #8:
score: 0
Accepted
time: 148ms
memory: 237276kb
input:
51 9921154
output:
340670552
result:
ok 1 number(s): "340670552"
Test #9:
score: 0
Accepted
time: 29ms
memory: 52036kb
input:
79 1801157
output:
620550406
result:
ok 1 number(s): "620550406"
Test #10:
score: 0
Accepted
time: 78ms
memory: 134532kb
input:
22 5417157
output:
457449071
result:
ok 1 number(s): "457449071"
Test #11:
score: 0
Accepted
time: 37ms
memory: 83016kb
input:
25 3210162
output:
36368303
result:
ok 1 number(s): "36368303"
Test #12:
score: 0
Accepted
time: 39ms
memory: 76888kb
input:
67 2919160
output:
935195555
result:
ok 1 number(s): "935195555"
Test #13:
score: 0
Accepted
time: 129ms
memory: 208984kb
input:
77 8613163
output:
482832472
result:
ok 1 number(s): "482832472"
Test #14:
score: 0
Accepted
time: 148ms
memory: 238024kb
input:
90 10000000
output:
275581651
result:
ok 1 number(s): "275581651"
Test #15:
score: 0
Accepted
time: 141ms
memory: 238172kb
input:
99 9999999
output:
126087169
result:
ok 1 number(s): "126087169"
Test #16:
score: 0
Accepted
time: 141ms
memory: 238128kb
input:
100 10000000
output:
451590067
result:
ok 1 number(s): "451590067"
Extra Test:
score: 0
Extra Test Passed