結果
問題 | No.2048 L(I+D)S |
ユーザー |
|
提出日時 | 2024-04-13 22:31:27 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 56 ms / 2,000 ms |
コード長 | 1,548 bytes |
コンパイル時間 | 602 ms |
コンパイル使用メモリ | 71,580 KB |
実行使用メモリ | 5,632 KB |
最終ジャッジ日時 | 2024-10-03 00:21:57 |
合計ジャッジ時間 | 1,842 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 |
ソースコード
#include <iostream> #include <vector> using namespace std; const long long MOD = 998244353LL; struct ModInt { long long x; ModInt(long long _x = 0) : x((_x % MOD + MOD) % MOD) {} ModInt operator+(const ModInt& other) const { return ModInt(x + other.x); } ModInt operator-(const ModInt& other) const { return ModInt(x - other.x); } ModInt operator*(const ModInt& other) const { return ModInt(x * other.x); } ModInt operator/(const ModInt& other) const { return *this * other.inv(); } ModInt pow(long long exp) const { if (exp == 0LL) return ModInt(1LL); ModInt a = pow(exp >> 1); a = a * a; if (exp & 1LL) return *this * a; return a; } ModInt inv() const { return pow(MOD - 2); } bool operator==(const ModInt& other) const { return x == other.x; } bool operator!=(const ModInt& other) const { return !(*this == other); } }; int main() { int n; cin >> n; const int facSize = 300000; vector<ModInt> fac(facSize); fac[0] = ModInt(1); for (int i = 1; i < facSize; ++i) { fac[i] = fac[i - 1] * ModInt(i); } auto helper = [&](int n, int m) -> ModInt { ModInt r = fac[n + m] / (fac[n - 2] * fac[m - 2] * ModInt(n) * ModInt(m) * ModInt(n + m - 1)); return r * r; }; ModInt ans(0); for (int k = 2; k <= n - 2; ++k) { ans = ans + helper(n - k, k); } cout << ans.x << endl; return 0; }