結果

問題 No.1693 Invasion
ユーザー kabipoyokabipoyo
提出日時 2021-12-24 17:43:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 298 ms / 2,000 ms
コード長 2,173 bytes
コンパイル時間 5,025 ms
コンパイル使用メモリ 276,560 KB
実行使用メモリ 128,536 KB
最終ジャッジ日時 2023-10-19 20:22:12
合計ジャッジ時間 8,602 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 190 ms
85,564 KB
testcase_10 AC 98 ms
42,368 KB
testcase_11 AC 36 ms
16,860 KB
testcase_12 AC 122 ms
50,848 KB
testcase_13 AC 48 ms
23,524 KB
testcase_14 AC 66 ms
32,520 KB
testcase_15 AC 36 ms
21,584 KB
testcase_16 AC 95 ms
44,760 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 272 ms
120,792 KB
testcase_19 AC 9 ms
8,644 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 284 ms
124,404 KB
testcase_22 AC 252 ms
105,028 KB
testcase_23 AC 298 ms
128,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef int64_t lint;
#define rep(i, n) for(int i=0; i<n; i++)
#define repx(i, l, n) for(int i=l; i<n; i++)
#define all(v) v.begin(), v.end()
#define show(x) cout << #x << ": " << x << endl;
#define list(x) cout << #x << ": " << x << "  ";
#define pb push_back
using vi = vector<lint>;
using vvi = vector<vector<lint>>;
template<class T> inline void vin(vector<T>& v) { rep(i, v.size()) cin >> v.at(i); }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline void drop(T x) { cout << x << endl; exit(0); }
template<class T> void vout(vector<T> v) { rep(i, v.size()) { cout << v.at(i) << ' '; } cout << endl; }
constexpr lint LINF = LLONG_MAX/2;
#define mp make_pair
using pint = pair<lint, lint>;
using mint = modint998244353;
using vm = vector<mint>;
struct combination {
	vector<mint> fact, ifact;
	combination(int n):fact(n+1),ifact(n+1) {
		assert(n < mint::mod());
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n]*ifact[k]*ifact[n-k];
	}
};

vector<vector<pair<lint, lint>>> G;
void dijkstra(int start, vector<lint> &dist) {
	lint a=0, b=0, x, y, N = G.size();
	dist.resize(N, LINF); dist[start] = 0;
	priority_queue<pint, vector<pint>, greater<pint>> PQ;
	PQ.push(make_pair(0, start));
	while (!PQ.empty()) {
		tie(x, a) = PQ.top(); PQ.pop();
		if (dist[a] < x) continue;
		for (auto p : G[a]) {
			tie(y, b) = p;
			if (chmin(dist[b], x+y)) PQ.push(make_pair(x+y, b));
		}
	}
}

int main() {
	lint N, M;
	cin >> N >> M;
	vi v(N);
	vin(v);

	mint a=1, b=0, c=0;
	lint x, y, z;
	G.resize(M+1);
	rep(i, N) {
		rep(j, M) {
			if (j + v[i] <= M) G[j].pb({1, j+v[i]});
		}
	}
	vi w;
	dijkstra(0, w);
	combination C(M+1);
	repx(i, 1, M+1) {
		if (w[i] == LINF) continue;
		a += C(M-w[i], i-w[i]);
	}
	std::cout << a.val() << '\n';
}
0