結果

問題 No.2058 Binary String
ユーザー ぷらぷら
提出日時 2022-08-26 21:34:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 966 bytes
コンパイル時間 2,034 ms
コンパイル使用メモリ 200,340 KB
実行使用メモリ 8,284 KB
最終ジャッジ日時 2023-08-04 00:58:01
合計ジャッジ時間 3,700 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
8,024 KB
testcase_01 AC 6 ms
8,048 KB
testcase_02 AC 8 ms
8,080 KB
testcase_03 AC 7 ms
8,096 KB
testcase_04 AC 7 ms
8,024 KB
testcase_05 AC 6 ms
8,076 KB
testcase_06 AC 7 ms
8,040 KB
testcase_07 AC 23 ms
8,072 KB
testcase_08 AC 9 ms
8,164 KB
testcase_09 AC 24 ms
8,024 KB
testcase_10 AC 13 ms
8,040 KB
testcase_11 AC 10 ms
8,020 KB
testcase_12 AC 16 ms
8,040 KB
testcase_13 AC 12 ms
8,040 KB
testcase_14 AC 12 ms
8,160 KB
testcase_15 AC 12 ms
8,080 KB
testcase_16 AC 12 ms
8,024 KB
testcase_17 AC 13 ms
8,028 KB
testcase_18 AC 6 ms
8,020 KB
testcase_19 AC 23 ms
8,284 KB
testcase_20 AC 20 ms
8,244 KB
testcase_21 AC 23 ms
8,024 KB
testcase_22 AC 24 ms
8,096 KB
testcase_23 AC 24 ms
8,104 KB
testcase_24 AC 25 ms
8,024 KB
testcase_25 AC 25 ms
8,100 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

constexpr int mod = 998244353;

long long fac[200005], finv[200005], inv[200005];

void COMinit() {
    fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1;
    for (int i = 2; i < 200005; 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;
}

long long modpow(long long a,long long b) {
    long long ans = 1;
    while(b) {
        if(b & 1) {
            (ans *= a) %= mod;
        }
        (a *= a) %= mod;
        b /= 2;
    }
    return ans;
}

int main() {
    COMinit();
    int N,K;
    cin >> N >> K;
    int ans = 0;
    for(int i = 1; i < N; i++) {
        ans += modpow(i,K)*COM(N-1,i)%mod;
        if(ans >= mod) ans -= mod;
    }
    cout << ans << endl;
}
0