QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#374643 | #8339. Rooted Tree | ucup-team228# | AC ✓ | 1391ms | 44408kb | C++20 | 2.7kb | 2024-04-02 16:11:43 | 2024-04-02 16:11:43 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string to_string(string a) { return '"' + a + '"'; }
string to_string(char a) { return "'" + string(1, a) + "'"; }
string to_string(const char* a) { return to_string((string) a); }
string to_string(bool a) { return a ? "true" : "false"; }
template <class T1, class T2>
string to_string(pair<T1, T2> a) {
return "(" + to_string(a.first) + ", " + to_string(a.second) + ")";
}
template <class T>
string to_string(T a) {
bool first = true; string res = "{";
for (const auto& i : a) {
if (!first) res += ", ";
first = false;
res += to_string(i);
}
res += "}";
return res;
}
void debug_out() { cerr << endl; }
template <class T1, class... T2>
void debug_out(T1 a, T2... b) {
cerr << " " << to_string(a);
debug_out(b...);
}
#ifdef LOCAL
#define out(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define out(...) 42
#endif
const int mod = 1e9 + 9;
int add(int a, int b) {
return a + b >= mod ? a + b - mod : a + b;
}
int sub(int a, int b) {
return a - b < 0 ? a - b + mod : a - b;
}
int mult(int a, int b) {
return int(1ll * a * b % mod);
}
int binpow(int a, int n) {
int res = 1;
for (; n >= 1; n >>= 1) {
if (n & 1) res = mult(res, a);
a = mult(a, a);
}
return res;
}
int inv(int a) {
return binpow(a, mod - 2);
}
#define div my_div
int div(int a, int b) {
return mult(a, inv(b));
}
const int N = 1e7 + 10;
int f[N];
int fact[N], inv_fact[N];
void init() {
fact[0] = 1;
for (int i = 1; i <= N - 1; i++) {
fact[i] = mult(fact[i - 1], i);
}
inv_fact[N - 1] = inv(fact[N - 1]);
for (int i = N - 2; i >= 0; i--) {
inv_fact[i] = mult(inv_fact[i + 1], i + 1);
}
}
int C(int n, int k) {
if (n < 0 || k < 0 || n < k) {
return 0;
} else {
return mult(fact[n], mult(inv_fact[k], inv_fact[n - k]));
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
// init();
int m, k;
cin >> m >> k;
f[0] = 0;
int ans = 0;
int tot = 1;
for (int i = 1; i <= k; i++) {
ans = add(ans, mult(add(f[i - 1], 1), m)); // (f[i - 1] + 1) * m
tot = add(tot, m - 1);
// int inv_tot = inv(tot);
// f[i] = add(mult(mult(m, inv_tot), add(f[i - 1], 1)), mult(mult(sub(tot, m), inv_tot), f[i - 1]));
f[i] = add(f[i - 1], div(m, tot));
}
cout << ans << "\n";
#ifdef LOCAL
cout << "\nTime elapsed: " << double(clock()) / CLOCKS_PER_SEC << " s.\n";
#endif
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5636kb
input:
6 2
output:
18
result:
ok 1 number(s): "18"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5640kb
input:
2 6
output:
600000038
result:
ok 1 number(s): "600000038"
Test #3:
score: 0
Accepted
time: 82ms
memory: 7648kb
input:
83 613210
output:
424200026
result:
ok 1 number(s): "424200026"
Test #4:
score: 0
Accepted
time: 933ms
memory: 32516kb
input:
48 6713156
output:
198541581
result:
ok 1 number(s): "198541581"
Test #5:
score: 0
Accepted
time: 1ms
memory: 5884kb
input:
1 111
output:
6216
result:
ok 1 number(s): "6216"
Test #6:
score: 0
Accepted
time: 1011ms
memory: 34488kb
input:
28 7304152
output:
457266679
result:
ok 1 number(s): "457266679"
Test #7:
score: 0
Accepted
time: 572ms
memory: 22012kb
input:
38 4101162
output:
232117382
result:
ok 1 number(s): "232117382"
Test #8:
score: 0
Accepted
time: 1373ms
memory: 44208kb
input:
51 9921154
output:
340670552
result:
ok 1 number(s): "340670552"
Test #9:
score: 0
Accepted
time: 252ms
memory: 14064kb
input:
79 1801157
output:
620550406
result:
ok 1 number(s): "620550406"
Test #10:
score: 0
Accepted
time: 750ms
memory: 26032kb
input:
22 5417157
output:
457449071
result:
ok 1 number(s): "457449071"
Test #11:
score: 0
Accepted
time: 443ms
memory: 17924kb
input:
25 3210162
output:
36368303
result:
ok 1 number(s): "36368303"
Test #12:
score: 0
Accepted
time: 406ms
memory: 15876kb
input:
67 2919160
output:
935195555
result:
ok 1 number(s): "935195555"
Test #13:
score: 0
Accepted
time: 1193ms
memory: 40484kb
input:
77 8613163
output:
482832472
result:
ok 1 number(s): "482832472"
Test #14:
score: 0
Accepted
time: 1373ms
memory: 43556kb
input:
90 10000000
output:
275581651
result:
ok 1 number(s): "275581651"
Test #15:
score: 0
Accepted
time: 1391ms
memory: 43284kb
input:
99 9999999
output:
126087169
result:
ok 1 number(s): "126087169"
Test #16:
score: 0
Accepted
time: 1384ms
memory: 44408kb
input:
100 10000000
output:
451590067
result:
ok 1 number(s): "451590067"
Extra Test:
score: 0
Extra Test Passed