結果

問題 No.1693 Invasion
ユーザー ktr216ktr216
提出日時 2021-10-01 22:11:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,423 bytes
コンパイル時間 1,814 ms
コンパイル使用メモリ 180,744 KB
実行使用メモリ 185,124 KB
最終ジャッジ日時 2023-09-26 17:33:30
合計ジャッジ時間 5,873 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,764 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 4 ms
4,500 KB
testcase_03 AC 7 ms
4,380 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 14 ms
4,376 KB
testcase_06 AC 22 ms
4,612 KB
testcase_07 AC 4 ms
4,380 KB
testcase_08 AC 10 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 <bits/stdc++.h>
#define rep(i, l, r) for (int i = (l); i < (r); i++)
using namespace std;

typedef long long ll;

ll MOD = 998244353;
vector<ll> f(1e5 + 1, 1);

ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

ll C(ll n, ll k) {
    ll ret = f[n] * mod_pow(f[k], MOD - 2, MOD) % MOD;
    ret = ret * mod_pow(f[n - k], MOD -2, MOD) % MOD;
    return ret;
}

int main() {
    ll ans = 0;
    int N, M;
    cin >> N >> M;
    rep(i, 0, M) f[i + 1] = f[i] * (i + 1) % MOD;
    vector<int> A(N);
    rep(i, 0, N) cin >> A[i];
    queue<pair<int, int>> q;
    vector<int> b(M + 1, 1e9); //x個選ぶのに最小でb(x)回必要;
    q.push(make_pair(0, 0));
    map<pair<int, int >, bool> done;
    while (!q.empty()) {
        int x = q.front().first, y = q.front().second;
        //cout << "(" << x << "," << y << ")";
        q.pop();
        b[y] = min(b[y], x);
        rep(i, 0, N) {
            if (y + A[i] <= M && !done[make_pair(x + 1, y + A[i])])  {
                q.push(make_pair(x + 1, y + A[i]));
                done[make_pair(x + 1, y + A[i])] = true;
            }
        }
    }
    rep(i, 0, M + 1) {
        //cout << i << " " << b[i] << endl;
        if (b[i] == 1e9) continue;
        ans += C(M - b[i], i - b[i]);
        ans %= MOD;
    }
    cout << ans << endl;
}
0