QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#348048 | #8339. Rooted Tree | ucup-team3113# | AC ✓ | 1390ms | 3680kb | C++20 | 2.3kb | 2024-03-09 16:44:04 | 2024-03-09 16:44:06 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define _ << " _ " <<
template<class T, class U>
ostream& operator<<(ostream &o, pair<T, U> x) {
return o << "(" << x.first << ", " << x.second << ")";
}
template<class> struct is_container : false_type {};
template<class... Ts> struct is_container<vector<Ts...>> : true_type {};
template<class... Ts> struct is_container<map<Ts...>> : true_type {};
template<class... Ts> struct is_container<unordered_map<Ts...>> : true_type {};
template<class... Ts> struct is_container<set<Ts...>> : true_type {};
template<class... Ts> struct is_container<unordered_set<Ts...>> : true_type {};
template<class... Ts> struct is_container<multiset<Ts...>> : true_type {};
template<class... Ts> struct is_container<unordered_multiset<Ts...>> : true_type {};
template<class T, class = typename enable_if<is_container<T>::value>::type>
ostream& operator<<(ostream &o, T x) {
int f = 1;
o << "{";
for (auto y : x) {
o << (f ? "" : ", ") << y;
f = 0;
}
return o << "}";
}
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const int MOD = 1e9 + 9;
int add(int a, int b) {
a += b;
if (a >= MOD) a -= MOD;
return a;
}
int sub(int a, int b) { return add(a, MOD - b); }
int mul(int a, int b) { return (ll)a * b % MOD; }
int pwr(int a, int b) {
int res = 1;
for (; b; b >>= 1) {
if (b & 1) res = mul(res, a);
a = mul(a, a);
}
return res;
}
int inv(int a) { return pwr(a, MOD - 2); }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int M, K;
cin >> M >> K;
int sum_leaves = 0, sum = 0, cnt_leaves = 1;
for (int i = 0; i < K; i++) {
int d = mul(sum_leaves, inv(cnt_leaves));
sum = add(sum, mul(M, d + 1));
sum_leaves = add(sum_leaves, sub(mul(M, d + 1), d));
cnt_leaves += M - 1;
}
cout << sum << '\n';
return 0;
}
// d -> doda M*(d+1)-d = (M-1)d + M na sumu dubina listova
// doda M*(d+1) na sumu dubina svih
// nakon k imamo 1 + (M-1)k listova
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3568kb
input:
6 2
output:
18
result:
ok 1 number(s): "18"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3624kb
input:
2 6
output:
600000038
result:
ok 1 number(s): "600000038"
Test #3:
score: 0
Accepted
time: 82ms
memory: 3680kb
input:
83 613210
output:
424200026
result:
ok 1 number(s): "424200026"
Test #4:
score: 0
Accepted
time: 935ms
memory: 3652kb
input:
48 6713156
output:
198541581
result:
ok 1 number(s): "198541581"
Test #5:
score: 0
Accepted
time: 1ms
memory: 3612kb
input:
1 111
output:
6216
result:
ok 1 number(s): "6216"
Test #6:
score: 0
Accepted
time: 1013ms
memory: 3564kb
input:
28 7304152
output:
457266679
result:
ok 1 number(s): "457266679"
Test #7:
score: 0
Accepted
time: 571ms
memory: 3524kb
input:
38 4101162
output:
232117382
result:
ok 1 number(s): "232117382"
Test #8:
score: 0
Accepted
time: 1378ms
memory: 3636kb
input:
51 9921154
output:
340670552
result:
ok 1 number(s): "340670552"
Test #9:
score: 0
Accepted
time: 251ms
memory: 3680kb
input:
79 1801157
output:
620550406
result:
ok 1 number(s): "620550406"
Test #10:
score: 0
Accepted
time: 753ms
memory: 3620kb
input:
22 5417157
output:
457449071
result:
ok 1 number(s): "457449071"
Test #11:
score: 0
Accepted
time: 447ms
memory: 3568kb
input:
25 3210162
output:
36368303
result:
ok 1 number(s): "36368303"
Test #12:
score: 0
Accepted
time: 406ms
memory: 3672kb
input:
67 2919160
output:
935195555
result:
ok 1 number(s): "935195555"
Test #13:
score: 0
Accepted
time: 1192ms
memory: 3652kb
input:
77 8613163
output:
482832472
result:
ok 1 number(s): "482832472"
Test #14:
score: 0
Accepted
time: 1390ms
memory: 3648kb
input:
90 10000000
output:
275581651
result:
ok 1 number(s): "275581651"
Test #15:
score: 0
Accepted
time: 1389ms
memory: 3608kb
input:
99 9999999
output:
126087169
result:
ok 1 number(s): "126087169"
Test #16:
score: 0
Accepted
time: 1383ms
memory: 3556kb
input:
100 10000000
output:
451590067
result:
ok 1 number(s): "451590067"
Extra Test:
score: 0
Extra Test Passed