結果

問題 No.2062 Sum of Subset mod 999630629
ユーザー kwm_tkwm_t
提出日時 2022-08-26 23:27:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 5,890 bytes
コンパイル時間 5,084 ms
コンパイル使用メモリ 263,412 KB
実行使用メモリ 11,124 KB
最終ジャッジ日時 2024-04-22 01:34:31
合計ジャッジ時間 12,022 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 21 ms
5,376 KB
testcase_09 AC 18 ms
5,376 KB
testcase_10 AC 16 ms
5,376 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
using mint = modint998244353;
const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
/*template<class T>
struct FormalPowerSeries : vector<T> {
	using vector<T>::vector;
	using vector<T>::operator=;
	using F = FormalPowerSeries;

	F operator-() const {
		F res(*this);
		for (auto &e : res) e = -e;
		return res;
	}
	F &operator*=(const T &g) {
		for (auto &e : *this) e *= g;
		return *this;
	}
	F &operator/=(const T &g) {
		assert(g != T(0));
		*this *= g.inv();
		return *this;
	}
	F &operator+=(const F &g) {
		int n = (*this).size(), m = g.size();
		rep(i, min(n, m)) (*this)[i] += g[i];
		return *this;
	}
	F &operator-=(const F &g) {
		int n = (*this).size(), m = g.size();
		rep(i, min(n, m)) (*this)[i] -= g[i];
		return *this;
	}
	F &operator<<=(const int d) {
		int n = (*this).size();
		(*this).insert((*this).begin(), d, 0);
		(*this).resize(n);
		return *this;
	}
	F &operator>>=(const int d) {
		int n = (*this).size();
		(*this).erase((*this).begin(), (*this).begin() + min(n, d));
		(*this).resize(n);
		return *this;
	}
	F inv(int d = -1) const {
		int n = (*this).size();
		assert(n != 0 && (*this)[0] != 0);
		if (d == -1) d = n;
		assert(d > 0);
		F res{ (*this)[0].inv() };
		while (res.size() < d) {
			int m = size(res);
			F f(begin(*this), begin(*this) + min(n, 2 * m));
			F r(res);
			f.resize(2 * m), internal::butterfly(f);
			r.resize(2 * m), internal::butterfly(r);
			rep(i, 2 * m) f[i] *= r[i];
			internal::butterfly_inv(f);
			f.erase(f.begin(), f.begin() + m);
			f.resize(2 * m), internal::butterfly(f);
			rep(i, 2 * m) f[i] *= r[i];
			internal::butterfly_inv(f);
			T iz = T(2 * m).inv(); iz *= -iz;
			rep(i, m) f[i] *= iz;
			res.insert(res.end(), f.begin(), f.begin() + m);
		}
		return { res.begin(), res.begin() + d };
	}

	// // fast: FMT-friendly modulus only
	// F &operator*=(const F &g) {
	//   int n = (*this).size();
	//   *this = convolution(*this, g);
	//   (*this).resize(n);
	//   return *this;
	// }
	// F &operator/=(const F &g) {
	//   int n = (*this).size();
	//   *this = convolution(*this, g.inv(n));
	//   (*this).resize(n);
	//   return *this;
	// }

	// // naive
	// F &operator*=(const F &g) {
	//   int n = (*this).size(), m = g.size();
	//   drep(i, n) {
	//     (*this)[i] *= g[0];
	//     rep2(j, 1, min(i+1, m)) (*this)[i] += (*this)[i-j] * g[j];
	//   }
	//   return *this;
	// }
	// F &operator/=(const F &g) {
	//   assert(g[0] != T(0));
	//   T ig0 = g[0].inv();
	//   int n = (*this).size(), m = g.size();
	//   rep(i, n) {
	//     rep2(j, 1, min(i+1, m)) (*this)[i] -= (*this)[i-j] * g[j];
	//     (*this)[i] *= ig0;
	//   }
	//   return *this;
	// }

	// sparse
	F &operator*=(vector<pair<int, T>> g) {
		int n = (*this).size();
		auto[d, c] = g.front();
		if (d == 0) g.erase(g.begin());
		else c = 0;
		drep(i, n) {
			(*this)[i] *= c;
			for (auto &[j, b] : g) {
				if (j > i) break;
				(*this)[i] += (*this)[i - j] * b;
			}
		}
		return *this;
	}
	F &operator/=(vector<pair<int, T>> g) {
		int n = (*this).size();
		auto[d, c] = g.front();
		assert(d == 0 && c != T(0));
		T ic = c.inv();
		g.erase(g.begin());
		rep(i, n) {
			for (auto &[j, b] : g) {
				if (j > i) break;
				(*this)[i] -= (*this)[i - j] * b;
			}
			(*this)[i] *= ic;
		}
		return *this;
	}

	// multiply and divide (1 + cz^d)
	void multiply(const int d, const T c) {
		int n = (*this).size();
		if (c == T(1)) drep(i, n - d) (*this)[i + d] += (*this)[i];
		else if (c == T(-1)) drep(i, n - d) (*this)[i + d] -= (*this)[i];
		else drep(i, n - d) (*this)[i + d] += (*this)[i] * c;
	}
	void divide(const int d, const T c) {
		int n = (*this).size();
		if (c == T(1)) rep(i, n - d) (*this)[i + d] -= (*this)[i];
		else if (c == T(-1)) rep(i, n - d) (*this)[i + d] += (*this)[i];
		else rep(i, n - d) (*this)[i + d] -= (*this)[i] * c;
	}

	T eval(const T &a) const {
		T x(1), res(0);
		for (auto e : *this) res += e * x, x *= a;
		return res;
	}

	F operator*(const T &g) const { return F(*this) *= g; }
	F operator/(const T &g) const { return F(*this) /= g; }
	F operator+(const F &g) const { return F(*this) += g; }
	F operator-(const F &g) const { return F(*this) -= g; }
	F operator<<(const int d) const { return F(*this) <<= d; }
	F operator>>(const int d) const { return F(*this) >>= d; }
	F operator*(const F &g) const { return F(*this) *= g; }
	F operator/(const F &g) const { return F(*this) /= g; }
	F operator*(vector<pair<int, T>> g) const { return F(*this) *= g; }
	F operator/(vector<pair<int, T>> g) const { return F(*this) /= g; }
};
using fps = FormalPowerSeries<mint>;
using sfps = vector<pair<int, mint>>;*/
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n; cin >> n;
	vector<int>a(n);
	int sum = 0;
	rep(i, n) {
		cin >> a[i];
		sum += a[i];
	}
	mint ans = 0;
	rep(i, n) {
		mint sub = pow_mod(2, n - 1, mod);
		sub *= a[i];
		ans += sub;
	}
	if (sum >= 999630629) {
		int over = sum - 999630629;
		vector<mint>f = { 1 };
		rep(i, n) {
			vector<mint> g = { 1,a[i] };
			auto h = convolution(f, g);
			if (h.size() > (over + 1))h.resize(over + 1);
			swap(f, h);
		}
		rep(i, f.size())ans -= f[i] * 999630629;
	}
	cout << ans.val() << endl;
	return 0;
}
0