結果

問題 No.1693 Invasion
ユーザー yu-ta38yu-ta38
提出日時 2021-10-01 22:33:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,497 bytes
コンパイル時間 999 ms
コンパイル使用メモリ 96,548 KB
実行使用メモリ 7,804 KB
最終ジャッジ日時 2023-09-26 18:36:44
合計ジャッジ時間 4,937 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,504 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 4 ms
4,376 KB
testcase_06 AC 4 ms
4,380 KB
testcase_07 AC 11 ms
4,380 KB
testcase_08 AC 3 ms
4,380 KB
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
using namespace std;

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main() {
    int n, m; cin >> n >> m;
    long long mod = 998244353;
    vector<int> a(n);
    vector<int> frag(m+1,0);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        frag[a[i]] = 1;
    }
    for(int i = 0; i < n; i++) {
        for(int j = 1; j <= m; j++) {
            if(frag[j] == 0) continue;
            if(j + a[i] > m) break;

            if(frag[j+a[i]] == 0) frag[j+a[i]] = frag[j] + 1;
            if(frag[j+a[i]] > frag[j] + 1) frag[j+a[i]] = frag[j] + 1;
        }
    }
    long long ans = 0;
    for(int j = 1; j <= m; j++) {
        // cout << j << ':';
        if(frag[j] == 0) {
            // cout << 0 << endl;
            continue;
        }

        long long value = 1, x = m - frag[j], r = j - frag[j], i = 1;
        if(r == 0) ans = (ans + 1) % mod;
        else {
            while(i <= r) {
                value = value * (x - i + 1);
                value %= mod;
                value =  value * modinv(i, mod) % mod;
                i++;
            }
            ans = (ans + value) % mod;
        }
        // cout << value << endl;
    }
    cout << ans + 1 << endl;
    return 0;
}
0