結果

問題 No.1186 長方形の敷き詰め
ユーザー sawfishsawfish
提出日時 2022-10-17 01:56:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 844 bytes
コンパイル時間 678 ms
コンパイル使用メモリ 64,984 KB
実行使用メモリ 7,688 KB
最終ジャッジ日時 2023-09-10 03:07:14
合計ジャッジ時間 5,059 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
7,668 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 WA -
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>

using namespace std;
using LL = long long;

constexpr int INF = 1 << 30;
constexpr LL INFL = 1L << 62;
constexpr int MOD = 998244353;

LL ncr(LL, LL, LL);

LL pow(LL, LL, LL);

int main() {
    int N, M;
    cin >> N >> M;

    LL ans = 0;
    for (int i = 0; i <= M / N; i++) {
        ans = (ans + ncr(M - (N * i) + i, M - (N * i), MOD)) % MOD;
    }

    cout << ans << endl;
}

LL ncr(LL n, LL r, LL m) {
    if (r == 0 || r == n) return 1L % m;
    LL a = 1, b = 1;
    for (LL i = n; i >= r + 1; i--) a = (a * i) % m;
    for (LL i = n - r; i >= 2; i--) b = (b * i) % m;
    return (a * pow(b, m - 2, m)) % m;
}

LL pow(LL a, LL b, LL m) {
    if (b == 0) return 1L % m;
    if (b == 1) return a % m;
    LL ret = pow(a, b / 2, m);
    ret = (ret * ret) % m;
    if (b % 2 == 1) ret = (ret * a) % m;
    return ret;
}
0