QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#725393 | #8339. Rooted Tree | Kopicy | TL | 1461ms | 108016kb | C++23 | 1.0kb | 2024-11-08 17:26:57 | 2024-11-08 17:26:57 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, a, b) for(int i=(a);i<=(b);++i)
#define drep(i, a, b) for(int i=(a);i>=(b);--i)
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(x) (int)x.size()
#define endl "\n"
const int N = 2e5, mod = 1e9 + 9, inf = 1e18;
int qpow(int a, int b) {
int res = 1;
while (b) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
int inv(int x) { return qpow(x, mod - 2); }
void solve() {
int m, k;
cin >> m >> k;
vector<int> g(k + 1), f(k + 1);
rep(i, 0, k - 1) {
g[i + 1] = (g[i] + (f[i] * inv(1 + i * (m - 1)) % mod + 1) * m % mod) %
mod;
f[i + 1] = (f[i] + (f[i] * inv(1 + i * (m - 1)) % mod + 1) * m % mod -
f[i] * inv(1 + i * (m - 1)) % mod + mod) % mod;
}
cout<<g[k]<<endl;
}
signed main() {
IOS
int64_t tt = 1;
//cin >> tt;
rep(kase, 1, tt) solve();
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3500kb
input:
6 2
output:
18
result:
ok 1 number(s): "18"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
2 6
output:
600000038
result:
ok 1 number(s): "600000038"
Test #3:
score: 0
Accepted
time: 134ms
memory: 12688kb
input:
83 613210
output:
424200026
result:
ok 1 number(s): "424200026"
Test #4:
score: 0
Accepted
time: 1461ms
memory: 108016kb
input:
48 6713156
output:
198541581
result:
ok 1 number(s): "198541581"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
1 111
output:
6216
result:
ok 1 number(s): "6216"
Test #6:
score: -100
Time Limit Exceeded
input:
28 7304152
output:
457266679