結果

問題 No.2299 Antitypoglycemia
ユーザー erbowlerbowl
提出日時 2023-05-12 21:30:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 3,439 bytes
コンパイル時間 2,162 ms
コンパイル使用メモリ 200,328 KB
実行使用メモリ 15,488 KB
最終ジャッジ日時 2024-05-06 11:06:24
合計ジャッジ時間 3,445 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
15,412 KB
testcase_01 AC 17 ms
15,488 KB
testcase_02 AC 17 ms
15,396 KB
testcase_03 AC 17 ms
15,360 KB
testcase_04 AC 17 ms
15,460 KB
testcase_05 AC 16 ms
15,360 KB
testcase_06 AC 16 ms
15,328 KB
testcase_07 AC 16 ms
15,360 KB
testcase_08 AC 17 ms
15,232 KB
testcase_09 AC 17 ms
15,232 KB
testcase_10 AC 17 ms
15,488 KB
testcase_11 AC 17 ms
15,384 KB
testcase_12 AC 18 ms
15,360 KB
testcase_13 AC 17 ms
15,360 KB
testcase_14 AC 17 ms
15,360 KB
testcase_15 AC 17 ms
15,260 KB
testcase_16 AC 17 ms
15,360 KB
testcase_17 AC 18 ms
15,364 KB
testcase_18 AC 18 ms
15,232 KB
testcase_19 AC 17 ms
15,304 KB
testcase_20 AC 17 ms
15,360 KB
testcase_21 AC 19 ms
15,488 KB
testcase_22 AC 17 ms
15,232 KB
testcase_23 AC 16 ms
15,232 KB
testcase_24 AC 17 ms
15,360 KB
testcase_25 AC 17 ms
15,360 KB
testcase_26 AC 17 ms
15,360 KB
testcase_27 AC 17 ms
15,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

typedef long long ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;
#define int long long
// こっちを使おう!
// __builtin_popcountll

// modint
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() const { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b, swap(a, b);
            u -= t * v, swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr istream& operator >> (istream& is, Fp<MOD>& x) noexcept {
        is >> x.val;
        x.val %= MOD;
        if (x.val < 0) x.val += MOD;
        return is;
    }
    friend constexpr ostream& operator << (ostream& os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD>& r, long long n) noexcept {
        if (n == 0) return 1;
        if (n < 0) return modpow(modinv(r), -n);
        auto t = modpow(r, n / 2);
        t = t * t;
        if (n & 1) t = t * r;
        return t;
    }
    friend constexpr Fp<MOD> modinv(const Fp<MOD>& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b, swap(a, b);
            u -= t * v, swap(u, v);
        }
        return Fp<MOD>(u);
    }
};

// const int MOD = 1000000007;
const int MOD = 998244353;
using mint = Fp<MOD>;

const int MAX = 510000;
// const int MOD = 998244353;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


signed main(){
    ll n,a,b;
    COMinit();
    std::cin >> n>>a>>b;
    if(a==b){
        std::cout << (fac[n]-fac[n-1]+MOD-fac[n-1]+MOD)%MOD << std::endl;
    }else{
        std::cout << (fac[n]-fac[n-1]+MOD-fac[n-1]+MOD+fac[n-2])%MOD << std::endl;
    }
}
0