結果

問題 No.2484 Add to Variables
ユーザー pockynypockyny
提出日時 2023-10-03 23:32:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 145 ms / 2,000 ms
コード長 1,118 bytes
コンパイル時間 2,237 ms
コンパイル使用メモリ 111,828 KB
実行使用メモリ 28,956 KB
最終ジャッジ日時 2023-10-03 23:32:14
合計ジャッジ時間 7,271 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
15,096 KB
testcase_01 AC 33 ms
15,100 KB
testcase_02 AC 33 ms
15,328 KB
testcase_03 AC 33 ms
15,300 KB
testcase_04 AC 33 ms
15,104 KB
testcase_05 AC 33 ms
15,276 KB
testcase_06 AC 33 ms
15,044 KB
testcase_07 AC 33 ms
15,108 KB
testcase_08 AC 33 ms
15,096 KB
testcase_09 AC 33 ms
15,104 KB
testcase_10 AC 39 ms
15,500 KB
testcase_11 AC 49 ms
16,840 KB
testcase_12 AC 68 ms
18,548 KB
testcase_13 AC 50 ms
16,704 KB
testcase_14 AC 92 ms
21,808 KB
testcase_15 AC 40 ms
15,484 KB
testcase_16 AC 95 ms
22,440 KB
testcase_17 AC 60 ms
18,100 KB
testcase_18 AC 69 ms
18,572 KB
testcase_19 AC 145 ms
28,448 KB
testcase_20 AC 37 ms
15,228 KB
testcase_21 AC 145 ms
28,572 KB
testcase_22 AC 39 ms
15,556 KB
testcase_23 AC 59 ms
18,444 KB
testcase_24 AC 108 ms
22,896 KB
testcase_25 AC 89 ms
21,924 KB
testcase_26 AC 60 ms
18,640 KB
testcase_27 AC 75 ms
18,608 KB
testcase_28 AC 89 ms
21,592 KB
testcase_29 AC 91 ms
21,964 KB
testcase_30 AC 47 ms
16,828 KB
testcase_31 AC 145 ms
28,956 KB
testcase_32 AC 108 ms
22,696 KB
testcase_33 AC 108 ms
22,940 KB
testcase_34 AC 62 ms
18,644 KB
testcase_35 AC 89 ms
22,400 KB
testcase_36 AC 61 ms
18,636 KB
testcase_37 AC 90 ms
22,396 KB
testcase_38 AC 89 ms
21,592 KB
testcase_39 AC 109 ms
22,576 KB
testcase_40 AC 36 ms
15,168 KB
testcase_41 AC 59 ms
18,432 KB
testcase_42 AC 50 ms
16,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <atcoder/modint>
#include <atcoder/convolution>

using namespace std;
using namespace atcoder;
using ll = long long;
using mint = modint998244353;
const int MX = 1000010;
mint f[MX],inv[MX],fi[MX];
constexpr ll mod = 998244353;
void solve(){
    inv[1] = 1;
    for(int i=2;i<MX;i++){
        inv[i] = mod - (mod/i)*inv[mod%i];
    }
    f[0] = fi[0] = 1;
    for(int i=1;i<MX;i++){
        f[i] = f[i-1]*i;
        fi[i] = fi[i-1]*inv[i];
    }
}

int a[200010];
int main(){
    solve();
    int i,n,m; cin >> n >> m;
    for(i=0;i<n;i++) cin >> a[i];
    vector<mint> ff(m + 1),gg(m + 1),hh(m + 1);
    for(i=0;i<=m;i++){
        if(a[0] - a[1] + i>=0) ff[i] = fi[i]*fi[a[0] - a[1] + i];
        if(a[1] - a[2] + i>=0) gg[i] = fi[i]*fi[a[1] - a[2] + i];
        if(a[2] - a[3] + i>=0) hh[i] = fi[i]*fi[a[2] - a[3] + i];
    }
    ff = convolution(ff,gg);
    ff = convolution(ff,hh);
    mint ans = 0;
    for(i=0;i<=m;i++){
        if(a[3] - i>=0 && (m - a[0]) - i>=0) ans += ff[i]*fi[a[3] - i]*fi[m - a[0] - i];
    }
    ans *= f[m];
    cout << ans.val() << "\n";
}
0