結果
問題 | No.2299 Antitypoglycemia |
ユーザー | AnchorBlues |
提出日時 | 2023-09-30 11:38:09 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 4,198 bytes |
コンパイル時間 | 2,182 ms |
コンパイル使用メモリ | 201,512 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-23 05:42:11 |
合計ジャッジ時間 | 3,253 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 3 ms
5,376 KB |
testcase_04 | AC | 3 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 3 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 3 ms
5,376 KB |
testcase_09 | AC | 3 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 3 ms
5,376 KB |
testcase_12 | AC | 3 ms
5,376 KB |
testcase_13 | AC | 4 ms
5,376 KB |
testcase_14 | AC | 2 ms
5,376 KB |
testcase_15 | AC | 2 ms
5,376 KB |
testcase_16 | AC | 2 ms
5,376 KB |
testcase_17 | AC | 2 ms
5,376 KB |
testcase_18 | AC | 3 ms
5,376 KB |
testcase_19 | AC | 3 ms
5,376 KB |
testcase_20 | AC | 4 ms
5,376 KB |
testcase_21 | AC | 4 ms
5,376 KB |
testcase_22 | AC | 3 ms
5,376 KB |
testcase_23 | AC | 2 ms
5,376 KB |
testcase_24 | AC | 2 ms
5,376 KB |
testcase_25 | AC | 2 ms
5,376 KB |
testcase_26 | AC | 2 ms
5,376 KB |
testcase_27 | AC | 2 ms
5,376 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; template <typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>; using pii = pair<int, int>; using pll = pair<ll, ll>; using Graph = vector<vector<int>>; const ll INF = 1LL << 60; const ll Z = 998244353; template <class T> void chmax(T& a, T b) { if (b > a) a = b; } template <class T> void chmin(T& a, T b) { if (b < a) a = b; } template <typename T, typename S> std::ostream& operator<<(std::ostream& os, const pair<T, S>& x) noexcept { return os << "(" << x.first << ", " << x.second << ")"; } template <typename T> void print_vector(vector<T> a) { cout << '['; for (int i = 0; i < a.size(); i++) { cout << a[i]; if (i != a.size() - 1) { cout << ", "; } } cout << ']' << endl; } template <ll MOD> class ModInt { public: constexpr ModInt() { val = 0; } constexpr ModInt(ll v) noexcept : val(v % MOD) { if (val < 0) val += MOD; } constexpr ll getval() const noexcept { return val; } constexpr ModInt operator-() const noexcept { if (val == 0) return 0; return MOD - val; } constexpr ModInt operator+(const ModInt& r) const noexcept { return ModInt(*this) += r; } constexpr ModInt operator-(const ModInt& r) const noexcept { return ModInt(*this) -= r; } constexpr ModInt operator*(const ModInt& r) const noexcept { return ModInt(*this) *= r; } constexpr ModInt operator/(const ModInt& r) const noexcept { return ModInt(*this) /= r; } constexpr ModInt& operator+=(const ModInt& r) noexcept { val += r.val; if (val >= MOD) val -= MOD; return *this; } constexpr ModInt& operator-=(const ModInt& r) noexcept { val -= r.val; if (val < 0) val += MOD; return *this; } constexpr ModInt& operator*=(const ModInt& r) noexcept { val = val * r.val % MOD; return *this; } constexpr ModInt& operator/=(const ModInt& r) noexcept { ll a = r.val, b = MOD, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); } val = val * u % MOD; if (val < 0) val += MOD; return *this; } constexpr bool operator==(const ModInt& r) const noexcept { return this->val == r.val; } constexpr bool operator!=(const ModInt& r) const noexcept { return this->val != r.val; } friend constexpr std::ostream& operator<<(std::ostream& os, const ModInt<MOD>& x) noexcept { return os << x.val; } // n乗 を MOD で割った余り constexpr ModInt<MOD> pow(ll n) noexcept { if (n == 0) return 1; auto t = this->pow(n / 2); t = t * t; if (n & 1) t = t * val; return t; } // 逆元 constexpr ModInt<MOD> inv() noexcept { ModInt<MOD> one = 1; return one / *this; } ModInt<MOD>& operator=(ll v) noexcept { val = v % MOD; return *this; } ModInt<MOD>& operator=(const ModInt<MOD>& v) noexcept { val = v.val % MOD; return *this; } private: ll val; }; using mint = ModInt<Z>; void solve() { ll N, A, B; cin >> N >> A >> B; if (A == B) { mint ret = 1; for (int i = 1; i <= N - 2; i++) { ret = ret * i; } ret *= (N - 2); ret *= (N - 1); std::cout << ret << "\n"; return; } // 最初の要素にBを選ぶ mint tmp1 = 1; for (int i = 1; i <= N - 2; i++) { tmp1 = tmp1 * i; } tmp1 *= (N - 1); tmp1 *= 1; // 最初の要素にAでもBでもないものを選ぶ mint tmp2 = 1; for (int i = 1; i <= N - 2; i++) { tmp2 = tmp2 * i; } tmp2 *= (N - 2); tmp2 *= (N - 2); std::cout << tmp1 + tmp2 << "\n"; } int main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); int T = 1; while (T--) { solve(); } return 0; }