QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#685510 | #8339. Rooted Tree | NCl3 | WA | 0ms | 81708kb | C++20 | 3.2kb | 2024-10-28 19:47:18 | 2024-10-28 19:47:19 |
Judging History
answer
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using ull = unsigned long long;
constexpr int N = 1e7 + 10;
constexpr int inf = 1e9 + 10;
constexpr ll llinf = 1e18 + 10;
constexpr int mod = 1e9 + 9;
void debug() {
std::cerr << "\n";
}
template<typename T, typename... Args>
void debug(T val, const Args&... args) {
std::cerr << val << " ";
debug(args...);
}
template<typename T>
void debug(const std::vector<T>& vec) {
for (const T& x : vec) std::cerr << x << ' ';std::cerr << "\n";
}
template <typename T>
T power(T a, int b) {
T ans = 1;
while (b) {
if (b & 1) ans *= a;
a *= a;
b >>= 1;
}
return ans;
}
template <int M>
struct modint {
modint() : x(0) {}
template <typename T> modint(T n) { n %= M; if (n < 0) n += M; this->x = n; }
modint& operator+=(const modint& r) { x += r.x; if (x >= M) x -= M; return *this; }
modint& operator-=(const modint& r) { x -= r.x; if (x < 0) x += M; return *this; }
modint& operator*=(const modint& r) { x = (int)((long long)x * r.x % M); return *this; }
modint inv(long long k = M - 2) const { return power(*this, k); }
modint& operator/=(const modint& r) { return *this *= r.inv(); }
modint& operator--() { if (--x == -1) x = M - 1; return *this; }
modint& operator++() { if (++x == M) x = 0; return *this; }
modint operator--(int) { modint t = *this; --*this; return t; }
modint operator++(int) { modint t = *this; ++*this; return t; }
modint operator-() const { return 0 - *this; }
modint operator+() const { return *this; }
constexpr int mod() const { return M; }
friend modint operator+(modint l, const modint& r) { return l += r; }
friend modint operator-(modint l, const modint& r) { return l -= r; }
friend modint operator*(modint l, const modint& r) { return l *= r; }
friend modint operator/(modint l, const modint& r) { return l /= r; }
friend bool operator==(const modint& l, const modint& r) { return l.x == r.x; }
friend bool operator!=(const modint& l, const modint& r) { return l.x != r.x; }
friend std::istream& operator>>(std::istream& in, modint& r) { return in >> r.x; }
friend std::ostream& operator<<(std::ostream& out, const modint& r) { return out << r.x; }
int x;
};
using mint = modint<mod>;
mint f[N], way[N];
void ncl3() {
int n, m;
std::cin >> m >> n;
way[0] = 1;
for (int i = 0; i < n; i++) {
f[i + 1] = f[i] + (m * f[i] - f[i] + i * m + (i * m + 1 - i) * m) * (way[i] * (i * m + 1 - i)).inv();
way[i + 1] = way[i] * (i * m + 1 - i);
// debug(f[i + 1], way[i + 1]);
}
std::cout << f[n] << "\n";
}
/*
预处理、找性质缩小范围、集合思想、正难则反、穷举
*/
int main() {
#ifdef LOCAL
clock_t time = clock();
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t = 1;
// std::cin >> t;
while (t--) {
ncl3();
}
#ifdef LOCAL
std::cout << "Time Used:" << clock() - time << "ms" << "\n";
#endif
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 81708kb
input:
6 2
output:
18
result:
ok 1 number(s): "18"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 81704kb
input:
2 6
output:
357952045
result:
wrong answer 1st numbers differ - expected: '600000038', found: '357952045'