結果

問題 No.2485 Add to Variables (Another)
ユーザー pockynypockyny
提出日時 2023-10-04 00:32:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 159 ms / 2,000 ms
コード長 1,088 bytes
コンパイル時間 2,453 ms
コンパイル使用メモリ 116,388 KB
実行使用メモリ 15,384 KB
最終ジャッジ日時 2023-10-04 00:32:19
合計ジャッジ時間 7,695 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
15,172 KB
testcase_01 AC 36 ms
15,240 KB
testcase_02 AC 37 ms
15,048 KB
testcase_03 AC 37 ms
15,144 KB
testcase_04 AC 36 ms
15,064 KB
testcase_05 AC 36 ms
15,116 KB
testcase_06 AC 36 ms
15,044 KB
testcase_07 AC 36 ms
15,384 KB
testcase_08 AC 36 ms
15,252 KB
testcase_09 AC 36 ms
15,120 KB
testcase_10 AC 36 ms
15,056 KB
testcase_11 AC 37 ms
15,100 KB
testcase_12 AC 51 ms
15,068 KB
testcase_13 AC 37 ms
15,100 KB
testcase_14 AC 38 ms
15,132 KB
testcase_15 AC 55 ms
15,188 KB
testcase_16 AC 37 ms
15,240 KB
testcase_17 AC 38 ms
15,160 KB
testcase_18 AC 38 ms
15,112 KB
testcase_19 AC 36 ms
15,156 KB
testcase_20 AC 36 ms
15,356 KB
testcase_21 AC 38 ms
15,064 KB
testcase_22 AC 36 ms
15,344 KB
testcase_23 AC 36 ms
15,172 KB
testcase_24 AC 37 ms
15,068 KB
testcase_25 AC 126 ms
15,296 KB
testcase_26 AC 93 ms
15,108 KB
testcase_27 AC 43 ms
15,072 KB
testcase_28 AC 60 ms
15,204 KB
testcase_29 AC 100 ms
15,160 KB
testcase_30 AC 126 ms
15,208 KB
testcase_31 AC 127 ms
15,212 KB
testcase_32 AC 126 ms
15,172 KB
testcase_33 AC 126 ms
15,120 KB
testcase_34 AC 127 ms
15,268 KB
testcase_35 AC 127 ms
15,208 KB
testcase_36 AC 126 ms
15,156 KB
testcase_37 AC 159 ms
15,144 KB
testcase_38 AC 127 ms
15,100 KB
testcase_39 AC 129 ms
15,116 KB
testcase_40 AC 129 ms
15,112 KB
testcase_41 AC 131 ms
15,100 KB
testcase_42 AC 36 ms
15,104 KB
testcase_43 AC 37 ms
15,120 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[2010],b[2010];
int main(){
    solve();
    int i,j,n,m; cin >> n >> m;
    for(i=0;i<n;i++) cin >> a[i];
    for(i=1;i<n;i++) b[i] = a[i] - a[i - 1]; 
    vector<mint> ff = {1};
    for(i=1;i<n;i++){
        vector<mint> g(m + 1);
        for(j=0;j<=m;j++){
            if(j + b[i]>=0) g[j] = fi[j]*fi[j + b[i]];
        }
        ff = convolution(ff,g);
        ff.resize(m + 1);
    }
    mint ans = 0;
    for(i=0;i<=m;i++){
        if(ff.size()>i && a[0]>=i && m - a[n - 1]>=i) ans += ff[i]*fi[a[0] - i]*fi[m - a[n - 1] - i];
    }
    ans *= f[m];
    cout << ans.val() << "\n";
}
0