結果

問題 No.2299 Antitypoglycemia
ユーザー Jeroen Op de BeekJeroen Op de Beek
提出日時 2023-05-12 21:27:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 2,977 bytes
コンパイル時間 2,027 ms
コンパイル使用メモリ 198,976 KB
実行使用メモリ 19,272 KB
最終ジャッジ日時 2023-08-19 03:51:52
合計ジャッジ時間 4,089 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
18,956 KB
testcase_01 AC 27 ms
19,072 KB
testcase_02 AC 28 ms
18,956 KB
testcase_03 AC 27 ms
18,956 KB
testcase_04 AC 27 ms
18,956 KB
testcase_05 AC 27 ms
19,040 KB
testcase_06 AC 27 ms
19,060 KB
testcase_07 AC 27 ms
19,000 KB
testcase_08 AC 27 ms
18,960 KB
testcase_09 AC 27 ms
19,048 KB
testcase_10 AC 27 ms
19,272 KB
testcase_11 AC 27 ms
19,040 KB
testcase_12 AC 28 ms
19,052 KB
testcase_13 AC 28 ms
19,012 KB
testcase_14 AC 27 ms
19,272 KB
testcase_15 AC 27 ms
18,956 KB
testcase_16 AC 27 ms
18,940 KB
testcase_17 AC 28 ms
18,984 KB
testcase_18 AC 27 ms
18,956 KB
testcase_19 AC 27 ms
18,944 KB
testcase_20 AC 28 ms
18,948 KB
testcase_21 AC 28 ms
18,968 KB
testcase_22 AC 27 ms
19,172 KB
testcase_23 AC 27 ms
19,112 KB
testcase_24 AC 27 ms
18,964 KB
testcase_25 AC 27 ms
18,956 KB
testcase_26 AC 28 ms
19,048 KB
testcase_27 AC 27 ms
19,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define all(x) begin(x),end(x)
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; }
#define debug(a) cerr << "(" << #a << ": " << a << ")\n";
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
const int mxN = 1e5+1, oo = 1e9;
const long long MD = 998244353 ;
template<long long MOD=MD> struct mdint {
    int d=0;
    mdint () {d=0;}
    mdint (long long _d) : d(_d%MOD){
        if(d<0) d+=MOD;
    };
    friend mdint& operator+=(mdint& a, const mdint& o) {
        a.d+=o.d; if(a.d>=MOD) a.d-=MOD;
        return a;
    }
    friend mdint& operator-=(mdint& a, const mdint& o) {
        a.d-=o.d; if(a.d<0) a.d+=MOD;
        return a;
    }
    friend mdint& operator*=(mdint& a, const mdint& o) {
        return a = mdint((ll)a.d*o.d);
    }
    mdint operator*(const mdint& o) const {
        mdint res = *this;
        res*=o;
        return res;
    }
    mdint operator+(const mdint& o) const {
        mdint res = *this;
        res+=o;
        return res;
    }
    mdint operator-(const mdint& o) const {
        mdint res = *this;
        res-=o;
        return res;
    }
    mdint operator^(long long b) const {
        mdint tmp = 1;
        mdint power = *this;
        while(b) {
            if(b&1) {
                tmp = tmp*power;
            }
            power = power*power;
            b/=2;
        }
        return tmp;
    }
    friend mdint operator/=(mdint& a, const mdint& o) {
        a *= (o^(MOD-2));
        return a;
    }
    mdint operator/(const mdint& o) {
        mdint res = *this;
        res/=o;
        return res;
    }
    bool operator==(const mdint& o) { return d==o.d;}
    bool operator!=(const mdint& o) { return d!=o.d;}
    friend istream& operator>>(istream& c, mdint& a) {return c >> a.d;}
    friend ostream& operator<<(ostream& c, const mdint& a) {return c << a.d;}
};
using  mint = mdint<MD>;
const int mxF = 2e6+2;
mint fact[mxF], ifact[mxF];
mint ncr(int a, int b) {
    if(b>a or a<0 or b<0) return 0;
    return fact[a]*ifact[b]*ifact[a-b];
}
void precomp() {
    fact[0]=1;
    for(int i=1;i<mxF;++i) {
        fact[i]=fact[i-1]*i;
    }
    ifact[mxF-1] = mint(1)/fact[mxF-1];
    for(int i=mxF-2;i>=0;--i) {
        ifact[i]=ifact[i+1]*(i+1);
    }
}
int main() {
    precomp();
    int n,a,b; cin >> n >> a >> b;
    mint ans=0;
    if(a==b) {
        // can not have it in front or back
        ans = fact[n];
        ans-=fact[n-1]*2;
    } else {
        ans=fact[n];
        ans-=fact[n-1]*2;
        ans+=fact[n-2];
    }
    cout << ans << '\n';
}
0