結果

問題 No.2633 Subsequence Combination Score
ユーザー shobonvipshobonvip
提出日時 2024-02-16 22:26:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 266 ms / 2,000 ms
コード長 2,174 bytes
コンパイル時間 4,870 ms
コンパイル使用メモリ 271,176 KB
実行使用メモリ 16,428 KB
最終ジャッジ日時 2024-02-16 22:26:19
合計ジャッジ時間 14,085 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
11,320 KB
testcase_01 AC 15 ms
11,320 KB
testcase_02 AC 68 ms
15,612 KB
testcase_03 AC 165 ms
15,192 KB
testcase_04 AC 159 ms
14,960 KB
testcase_05 AC 158 ms
14,992 KB
testcase_06 AC 165 ms
14,912 KB
testcase_07 AC 163 ms
15,036 KB
testcase_08 AC 39 ms
11,960 KB
testcase_09 AC 208 ms
15,856 KB
testcase_10 AC 207 ms
15,968 KB
testcase_11 AC 208 ms
15,832 KB
testcase_12 AC 206 ms
15,888 KB
testcase_13 AC 211 ms
15,788 KB
testcase_14 AC 205 ms
15,772 KB
testcase_15 AC 206 ms
16,088 KB
testcase_16 AC 206 ms
15,600 KB
testcase_17 AC 214 ms
15,608 KB
testcase_18 AC 210 ms
15,936 KB
testcase_19 AC 252 ms
16,236 KB
testcase_20 AC 251 ms
16,156 KB
testcase_21 AC 251 ms
16,024 KB
testcase_22 AC 253 ms
16,428 KB
testcase_23 AC 256 ms
16,164 KB
testcase_24 AC 258 ms
15,840 KB
testcase_25 AC 258 ms
15,996 KB
testcase_26 AC 255 ms
15,948 KB
testcase_27 AC 262 ms
15,892 KB
testcase_28 AC 266 ms
15,952 KB
testcase_29 AC 14 ms
11,320 KB
testcase_30 AC 14 ms
11,320 KB
testcase_31 AC 14 ms
11,320 KB
testcase_32 AC 15 ms
11,320 KB
testcase_33 AC 204 ms
15,500 KB
testcase_34 AC 206 ms
15,500 KB
testcase_35 AC 204 ms
15,788 KB
testcase_36 AC 213 ms
15,968 KB
testcase_37 AC 205 ms
15,664 KB
testcase_38 AC 230 ms
15,536 KB
testcase_39 AC 205 ms
15,632 KB
testcase_40 AC 203 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