結果
問題 | No.2351 Butterfly in Summer |
ユーザー | tsugutsugu |
提出日時 | 2023-06-17 01:20:03 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 3,225 bytes |
コンパイル時間 | 2,886 ms |
コンパイル使用メモリ | 249,164 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-24 18:11:41 |
合計ジャッジ時間 | 4,237 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 1 ms
6,944 KB |
testcase_03 | AC | 3 ms
6,940 KB |
testcase_04 | AC | 1 ms
6,940 KB |
testcase_05 | AC | 4 ms
6,940 KB |
testcase_06 | AC | 3 ms
6,940 KB |
testcase_07 | AC | 4 ms
6,944 KB |
testcase_08 | AC | 3 ms
6,944 KB |
testcase_09 | AC | 3 ms
6,944 KB |
testcase_10 | AC | 3 ms
6,944 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 2 ms
6,944 KB |
testcase_13 | AC | 3 ms
6,940 KB |
testcase_14 | AC | 4 ms
6,940 KB |
testcase_15 | AC | 4 ms
6,940 KB |
testcase_16 | AC | 3 ms
6,940 KB |
testcase_17 | AC | 2 ms
6,940 KB |
testcase_18 | AC | 3 ms
6,944 KB |
testcase_19 | AC | 2 ms
6,944 KB |
testcase_20 | AC | 3 ms
6,940 KB |
testcase_21 | AC | 3 ms
6,940 KB |
testcase_22 | AC | 1 ms
6,944 KB |
testcase_23 | AC | 3 ms
6,944 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.hpp" #else #define debug(...) 1 #endif template <int m> struct modint { unsigned int v = 0; static constexpr int mod() { return m; } static constexpr unsigned int umod() { return m; } unsigned int val() { return v; } modint() : v(0) {} modint(long long _v) { long long x = (long long)(_v % umod()); if (x < 0) { x += umod(); } v = (unsigned int) x; } modint operator+() const { return *this; } modint operator-() const { return modint() - *this; } modint(const modint &rhs) { v = rhs.v; } modint &operator+=(const modint &rhs) { v += rhs.v; if (v >= umod()) { v -= umod(); } return *this; } modint operator+(const modint &rhs) const { return modint(*this) += rhs; } modint &operator-=(const modint &rhs) { v -= rhs.v; if (v >= umod()) { v += umod(); } return *this; } modint operator-(const modint &rhs) const { return modint(*this) -= rhs; } modint &operator*=(const modint &rhs) { unsigned long long x = v; x *= rhs.v; v = (unsigned int) (x % umod()); return *this; } modint operator*(const modint &rhs) const { return modint(*this) *= rhs; } template <typename T> modint pow(T n) const { modint x = *this, ret = 1; while (n) { if (n & 1) ret *= x; x *= x; n >>= 1; } return ret; } modint inv() const { return pow(umod() - 2); } modint &operator/=(const modint &rhs) { *this *= rhs.inv(); return *this; } modint operator/(const modint &rhs) const { return modint(*this) /= rhs; } friend istream &operator>>(istream &is, modint &v) { long long x; is >> x; v.v = x; return is; } friend ostream &operator<<(ostream &os, modint &v) { return os << v.v; } }; constexpr int md = 998244353; // constexpr int md = 1000000007; vector<modint<md>> fact, inv, inv_fact; void cominit(int MAX) { fact.resize(MAX + 1); inv.resize(MAX + 1); inv_fact.resize(MAX + 1); fact[0] = fact[1] = 1; inv_fact[0] = inv_fact[1] = 1; inv[1] = 1; for (int i = 2; i <= MAX; i++) { fact[i] = fact[i - 1] * i; inv[i] = -inv[md % i] * (modint<md>) (md / i); inv_fact[i] = inv_fact[i - 1] * inv[i]; } } template <typename T> modint<md> Com(T n, T k) { assert(n < (int) fact.size() && k < (int) fact.size()); if (n < k) return 0; if (n < 0 || k < 0) return 0; return fact[n] * inv_fact[k] * inv_fact[n - k]; } template <typename T> modint<md> Per(T n, T k) { assert(n < (int) fact.size() && k < (int) fact.size()); if (n < k) return 0; if (n < 0 || k < 0) return 0; return fact[n] * inv_fact[n - k]; } using Mint = modint<md>; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, k; cin >> n >> k; cominit(n); Mint ans = Mint(n) * k * (k - 1) / Mint(k).pow(n); cout << ans << '\n'; }