結果

問題 No.2633 Subsequence Combination Score
ユーザー shobonvipshobonvip
提出日時 2024-02-16 22:25:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,173 bytes
コンパイル時間 6,239 ms
コンパイル使用メモリ 271,180 KB
実行使用メモリ 16,428 KB
最終ジャッジ日時 2024-02-16 22:25:26
合計ジャッジ時間 13,022 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
11,320 KB
testcase_01 AC 13 ms
11,320 KB
testcase_02 AC 64 ms
15,612 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 15 ms
11,320 KB
testcase_30 AC 13 ms
11,320 KB
testcase_31 AC 13 ms
11,320 KB
testcase_32 AC 13 ms
11,320 KB
testcase_33 AC 189 ms
15,500 KB
testcase_34 AC 186 ms
15,500 KB
testcase_35 AC 207 ms
15,788 KB
testcase_36 AC 190 ms
15,968 KB
testcase_37 AC 190 ms
15,664 KB
testcase_38 AC 189 ms
15,536 KB
testcase_39 AC 191 ms
15,632 KB
testcase_40 AC 213 ms
15,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/

/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/

typedef long long ll;

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)

template <typename T> bool chmin(T &a, const T &b) {
	if (a <= b) return false;
	a = b;
	return true;
}

template <typename T> bool chmax(T &a, const T &b) {
	if (a >= b) return false;
	a = b;
	return true;
}

template <typename T> T max(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
	return ret;
}

template <typename T> T min(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
	return ret;
}

template <typename T> T sum(vector<T> &a){
	T ret = 0;
	for (int i=0; i<(int)a.size(); i++) ret += a[i];
	return ret;
}

//defmodfact
const int COMinitMAX = 998444;
mint fact[COMinitMAX+1], factinv[COMinitMAX+1];

void modfact(){
	fact[0] = 1;
	for (int i=1; i<=COMinitMAX; i++){
		fact[i] = fact[i-1] * i;
	}
	factinv[COMinitMAX] = fact[COMinitMAX].inv();
	for (int i=COMinitMAX-1; i>=0; i--){
		factinv[i] = factinv[i+1] * (i+1);
	}
}

mint cmb(int a, int b){
	if (a<b || b<0) return mint(0);
	return fact[a]*factinv[b]*factinv[a-b];
}
//--------


int main(){
	modfact();
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n; cin >> n;
	vector<int> a(n);
	rep(i,0,n) cin >> a[i];

	vector<mint> dp(n, mint(1));

	auto dfs = [&](auto self, int l, int r) -> void {
		if (r - l <= 1){
			return;
		}

		int m = (l + r) / 2;
		self(self, l, m);

		vector<mint> tar(a[l] - a[r-1] + 1);
		rep(i,l,m){
			tar[a[l] - a[i]] = dp[i] * fact[a[i]];
		}


		vector<mint> q(a[l] - a[r-1] + 1);
		rep(i,0,a[l]-a[r-1]+1){
			q[i] = factinv[i];
		}

		vector<mint> tmp = convolution(tar, q);
		rep(i,m,r){
			// x + a[r-1] + y = a[i]
			dp[i] += tmp[a[l] - a[i]] * factinv[a[i]];
		}

		self(self, m, r);
	};

	dfs(dfs, 0, n);

	cout << sum(dp).val() << '\n';
}

0