結果
問題 | No.1006 Share an Integer |
ユーザー | polylogK |
提出日時 | 2020-12-19 00:13:58 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,353 bytes |
コンパイル時間 | 860 ms |
コンパイル使用メモリ | 78,860 KB |
実行使用メモリ | 34,688 KB |
最終ジャッジ日時 | 2024-09-21 09:31:22 |
合計ジャッジ時間 | 1,932 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
ソースコード
#line 1 "main.cpp" #include <stdio.h> #include <vector> #line 1 "/home/ecasdqina/cpcpp/libs/library_cpp/math/modint.hpp" #include <iostream> namespace cplib { template <std::uint_fast64_t Modulus> class modint { using u32 = std::uint_fast32_t; using u64 = std::uint_fast64_t; using i32 = std::int_fast32_t; using i64 = std::int_fast64_t; inline u64 apply(i64 x) { return (x < 0 ? x + Modulus : x); }; public: u64 a; static constexpr u64 mod = Modulus; constexpr modint(const i64& x = 0) noexcept: a(apply(x % (i64)Modulus)) {} constexpr modint operator+(const modint& rhs) const noexcept { return modint(*this) += rhs; } constexpr modint operator-(const modint& rhs) const noexcept { return modint(*this) -= rhs; } constexpr modint operator*(const modint& rhs) const noexcept { return modint(*this) *= rhs; } constexpr modint operator/(const modint& rhs) const noexcept { return modint(*this) /= rhs; } constexpr modint operator^(const u64& k) const noexcept { return modint(*this) ^= k; } constexpr modint operator^(const modint& k) const noexcept { return modint(*this) ^= k.value(); } constexpr modint operator-() const noexcept { return modint(Modulus - a); } constexpr modint operator++() noexcept { return (*this) = modint(*this) + 1; } constexpr modint operator--() noexcept { return (*this) = modint(*this) - 1; } const bool operator==(const modint& rhs) const noexcept { return a == rhs.a; }; const bool operator!=(const modint& rhs) const noexcept { return a != rhs.a; }; const bool operator<=(const modint& rhs) const noexcept { return a <= rhs.a; }; const bool operator>=(const modint& rhs) const noexcept { return a >= rhs.a; }; const bool operator<(const modint& rhs) const noexcept { return a < rhs.a; }; const bool operator>(const modint& rhs) const noexcept { return a > rhs.a; }; constexpr modint& operator+=(const modint& rhs) noexcept { a += rhs.a; if (a >= Modulus) a -= Modulus; return *this; } constexpr modint& operator-=(const modint& rhs) noexcept { if (a < rhs.a) a += Modulus; a -= rhs.a; return *this; } constexpr modint& operator*=(const modint& rhs) noexcept { a = a * rhs.a % Modulus; return *this; } constexpr modint& operator/=(modint rhs) noexcept { u64 exp = Modulus - 2; while (exp) { if (exp % 2) (*this) *= rhs; rhs *= rhs; exp /= 2; } return *this; } constexpr modint& operator^=(u64 k) noexcept { auto b = modint(1); while(k) { if(k & 1) b = b * (*this); (*this) *= (*this); k >>= 1; } return (*this) = b; } constexpr modint& operator=(const modint& rhs) noexcept { a = rhs.a; return (*this); } const modint inverse() const { return modint(1) / *this; } const modint power(i64 k) const { if(k < 0) return modint(*this).inverse() ^ (-k); return modint(*this) ^ k; } explicit operator bool() const { return a; } explicit operator u64() const { return a; } constexpr u64& value() noexcept { return a; } constexpr const u64& value() const noexcept { return a; } friend std::ostream& operator<<(std::ostream& os, const modint& p) { return os << p.a; } friend std::istream& operator>>(std::istream& is, modint& p) { u64 t; is >> t; p = modint(t); return is; } }; } #line 5 "main.cpp" using mint = cplib::modint<998244353>; int main() { int n, m, k; scanf("%d%d%d", &n, &m, &k); std::vector<mint> fact(n + 1, 1), factinv(n + 1, 1); for(int i = 0; i < n; i++) fact[i + 1] = fact[i] * (i + 1); factinv[n] = fact[n].inverse(); for(int i = n - 1; i > 0; i--) factinv[i] = factinv[i + 1] * (i + 1); auto comb = [&](int n, int r) { return fact[n] * factinv[r] * factinv[n - r] ;}; std::vector<int> prime, mip(m + k + 1); mip[0] = mip[1] = -1; for(int i = 2; i < mip.size(); i++) { if(mip[i] == 0) { mip[i] = i; prime.push_back(i); } for(int j = 0; j < prime.size() and prime[j] <= mip[i] and i * prime[j] < mip.size(); j++) { mip[i * prime[j]] = prime[j]; } } std::vector<mint> pow(m + k + 1); pow[1] = 1; for(auto p: prime) pow[p] = mint(p).power(n); for(int i = 4; i < pow.size(); i++) pow[i] = pow[i] * pow[mip[i]]; mint ans = 0; for(int i = 0; i <= k; i++) ans += comb(k, i) * pow[k + m - i] / fact[n] * (i % 2 ? -1 : 1); printf("%lld\n", (comb(m, k) * fact[n] * ans).value()); return 0; }