結果

問題 No.2130 分配方法の数え上げ mod 998244353
ユーザー T101010101T101010101
提出日時 2022-12-12 15:39:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 3,073 bytes
コンパイル時間 3,240 ms
コンパイル使用メモリ 252,172 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-04-24 06:20:49
合計ジャッジ時間 9,077 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 12 ms
11,008 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 11 ms
11,008 KB
testcase_06 AC 11 ms
11,008 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 11 ms
11,008 KB
testcase_11 AC 11 ms
11,008 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 13 ms
11,008 KB
testcase_14 AC 11 ms
11,008 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 11 ms
11,008 KB
testcase_17 AC 12 ms
11,008 KB
testcase_18 AC 16 ms
11,008 KB
testcase_19 AC 15 ms
11,008 KB
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma region Macros

#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
// using namespace __gnu_cxx;

#define TO_STRING(var) # var
#define pb emplace_back
#define int ll
#define endl '\n'

using ll = long long;
using ld = long double;
const ld PI = acos(-1);
const ld EPS = 1e-10;
const int INF = 1 << 30;
const ll INFL = 1LL << 62;
const int MOD = 998244353;
// const int MOD = 1000000007;

int ceil(int x, int y) {return (x > 0 ? (x + y - 1) / y : x / y);}
int POW(int x, int y) {
    if (y != (int)(y) or y < 0 or x != 0 && x != 1 && y > 64) {cout << "Error" << endl;return 0;}
    if (y == 0) return 1;
    if (y % 2 == 0) return POW(x * x, y / 2);
    return x * POW(x, y - 1);
}

__attribute__((constructor))
void constructor() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
}

#pragma endregion

template<int mod> class modint{
public:
    int val = 0;
    modint(int x = 0) { while (x < 0) x += mod; val = x % mod; }
    modint(const modint &r) { val = r.val; } // コピーコンストラクタ

    modint operator -(){ return modint(-val); } // 単項
    modint operator +(const modint &r) { return modint(*this) += r; }
    modint operator -(const modint &r) { return modint(*this) -= r; }
    modint operator *(const modint &r) { return modint(*this) *= r; }
    modint operator /(const modint &r) { return modint(*this) /= r; }

    modint &operator +=(const modint &r) {
        val += r.val;
        if (val >= mod) val -= mod;
        return *this;
    }
    modint &operator -=(const modint &r) {
        if (val < r.val) val += mod;
        val -= r.val;
        return *this;
    }
    modint &operator *=(const modint &r) {
        val = val * r.val % mod;
        return *this;
    }
    modint &operator /=(const modint &r) {
        int a = r.val, b = mod, u = 1, v = 0;
        while (b) {
            int 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;
    }

    bool operator ==(const modint& r) { return this -> val == r.val; }
    bool operator <(const modint& r) { return this -> val < r.val; }
    bool operator !=(const modint& r) { return this -> val != r.val; }
};

using mint = modint<MOD>;

istream &operator >>(istream &is, mint& x) {
    int t; is >> t;
    x = t;
    return (is);
}
ostream &operator <<(ostream &os, const mint& x) {
    return os << x.val;
}

mint modpow(const mint &a, int n) {
    if (n == 0) return 1;
    mint t = modpow(a, n / 2);
    t = t * t;
    if (n & 1) t = t * a;
    return t;
}

signed main() {
    int N, M;
	cin >> N >> M;
	if (M > N) {cout << 0 << endl; return 0;}
	if (M == N) {cout << 1 << endl; return 0;}

	mint zen = 1;
	zen = modpow(2LL, N);

	vector<mint> R(1e6 + 1);
    R[0] = 1;
    for (int i = 1; i <= 1e6; i++) {
        R[i] = R[i - 1] * i;
    }

	mint yo = 0;
	for (int i = 0; i < M; i++) {
		mint chose = R[N] / R[i] / R[N - i];
		yo += chose;
	}
	cout << zen - yo << endl;
}
0