結果

問題 No.2058 Binary String
ユーザー suisui
提出日時 2022-08-27 04:32:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 1,749 bytes
コンパイル時間 2,191 ms
コンパイル使用メモリ 196,556 KB
実行使用メモリ 15,360 KB
最終ジャッジ日時 2024-04-22 05:22:09
合計ジャッジ時間 3,768 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
15,196 KB
testcase_01 AC 16 ms
15,180 KB
testcase_02 AC 18 ms
15,184 KB
testcase_03 AC 16 ms
15,316 KB
testcase_04 AC 15 ms
15,288 KB
testcase_05 AC 15 ms
15,164 KB
testcase_06 AC 17 ms
15,332 KB
testcase_07 AC 31 ms
15,136 KB
testcase_08 AC 19 ms
15,232 KB
testcase_09 AC 31 ms
15,312 KB
testcase_10 AC 23 ms
15,344 KB
testcase_11 AC 19 ms
15,196 KB
testcase_12 AC 24 ms
15,140 KB
testcase_13 AC 22 ms
15,104 KB
testcase_14 AC 21 ms
15,360 KB
testcase_15 AC 19 ms
15,232 KB
testcase_16 AC 21 ms
15,180 KB
testcase_17 AC 23 ms
15,232 KB
testcase_18 AC 16 ms
15,176 KB
testcase_19 AC 31 ms
15,180 KB
testcase_20 AC 29 ms
15,308 KB
testcase_21 AC 32 ms
15,176 KB
testcase_22 AC 31 ms
15,292 KB
testcase_23 AC 31 ms
15,232 KB
testcase_24 AC 32 ms
15,232 KB
testcase_25 AC 32 ms
15,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n+1); i++)
#define repn(i,a,b) for (int i = (int)(a) ; i < (int)(b+1); i++)
#define repv(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) ((int)(x).size())
#define cauto const auto&
#define bit(n) (1LL<<(n))
#define uni(v) v.erase( unique(v.begin(), v.end()), v.end() );
using ll = long long;
using P = pair<int,int>;
using PP = pair<int, P>;
using Graph = vector<vector<int>>;
#ifdef LOCAL
    #include <debug.hpp>
    #define debug(...) debug::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
    #define debug(...) (static_cast<void>(0))
#endif

vector<ll> fac(510000,0),finv(510000,0),inv(510000,0);

void init() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < 510000; i++){
        fac[i] = (fac[i - 1] * i )% 998244353;
        inv[i] = (-inv[998244353%i] * (998244353/ i)) % 998244353 ;
        finv[i] =( finv[i - 1] * inv[i] ) % 998244353;
    }
}

ll combination(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return (fac[n] * (finv[k] * finv[n - k] % 998244353)) % 998244353;
}

ll pow_mod(ll a, ll b, ll mod = 998244353){
    ll res = 1;
    while(b > 0){
        if(b & 1) res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}

int main(){
    int n,k;
    cin >> n >> k;
    ll ans = 0;
    init();
    rep1(i,n-1){
        ans += combination(n-1,i) * pow_mod(i,k) % 998244353;
        ans %= 998244353;
    }
    if(ans < 0){
        ans += 998244353;
    }
    cout << ans << endl;
    return 0;
}
0