結果
問題 | No.3095 Many Min Problems |
ユーザー |
![]() |
提出日時 | 2025-04-07 02:18:11 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 133 ms / 2,000 ms |
コード長 | 3,241 bytes |
コンパイル時間 | 3,038 ms |
コンパイル使用メモリ | 275,864 KB |
実行使用メモリ | 7,844 KB |
最終ジャッジ日時 | 2025-04-07 02:18:18 |
合計ジャッジ時間 | 6,100 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
#include <bits/stdc++.h> #define ALL(x) (x).begin(), (x).end() #define LB(v, x) (int)(lower_bound(ALL(v), x) - (v).begin()) #define UQ(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end()) #define IO ios::sync_with_stdio(false), cin.tie(nullptr); #define chmax(a, b) (a) = (a) < (b) ? (b) : (a) #define chmin(a, b) (a) = (a) < (b) ? (a) : (b) using namespace std; using ll = long long; const int INF = 1e9 + 10; const ll INFL = 4e18; /// @file modint.hpp /// @brief ModInt template <ll MOD> struct ModInt { ModInt(ll x = 0) { value = (x >= 0 ? x % MOD : MOD - (-x) % MOD); } ModInt operator-() const { return ModInt(-value); } ModInt operator+() const { return ModInt(*this); } ModInt& operator+=(const ModInt& other) { value += other.value; if (value >= MOD) value -= MOD; return *this; } ModInt& operator-=(const ModInt& other) { value += MOD - other.value; if (value >= MOD) value -= MOD; return *this; } ModInt& operator*=(const ModInt other) { value = value * other.value % MOD; return *this; } ModInt& operator/=(ModInt other) { (*this) *= other.inv(); return *this; } ModInt operator+(const ModInt& other) const { return ModInt(*this) += other; } ModInt operator-(const ModInt& other) const { return ModInt(*this) -= other; } ModInt operator*(const ModInt& other) const { return ModInt(*this) *= other; } ModInt operator/(const ModInt& other) const { return ModInt(*this) /= other; } ModInt pow(ll x) const { ModInt ret(1), mul(value); while (x) { if (x & 1) ret *= mul; mul *= mul; x >>= 1; } return ret; } ModInt inv() const { return pow(MOD - 2); } bool operator==(const ModInt& other) const { return value == other.value; } bool operator!=(const ModInt& other) const { return value != other.value; } friend ostream& operator<<(ostream& os, const ModInt& x) { return os << x.value; } friend istream& operator>>(istream& is, ModInt& x) { ll v; is >> v; x = ModInt<MOD>(v); return is; } ll val() { return value; } static constexpr ll get_mod() { return MOD; } private: ll value; }; using Mod998 = ModInt<998244353>; using Mod107 = ModInt<1000000007>; using mint = Mod998; int main() { ll N, M; cin >> N >> M; mint p1 = 0; { for (int j = 1; j <= M; j++) { mint add = j; int start = M - j + 1; mint r = mint(M - j + 1) / M; if (r.val() == 1) { add *= (mint)start * N; } else { add *= mint(start) * (r.pow(N) - 1) / (r - 1); } p1 += add; } } mint p2 = 0; { for (int j = 1; j < M; j++) { mint add = j; int start = M - j; mint r = mint(M - j) / M; if (r.val() == 1) { add *= (mint)start * N; } else { add *= mint(start) * (mint(r).pow(N) - 1) / (r - 1); } p2 += add; } } mint ans = p1 - p2; ans *= mint(M).pow(N - 1); cout << ans << endl; }