結果

問題 No.2062 Sum of Subset mod 999630629
ユーザー 沙耶花沙耶花
提出日時 2022-08-26 23:06:39
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 856 bytes
コンパイル時間 5,021 ms
コンパイル使用メモリ 264,020 KB
最終ジャッジ日時 2025-01-31 05:33:49
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10 WA * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000000
#define Inf64 4000000000000000001

int M = 999630629;
int main() {
	
	int n;
	cin>>n;
	vector<int> a(n);
	int S = 0;
	rep(i,n){
		cin>>a[i];
		S += a[i];
	}
	mint ans;
	if(S < M){
		ans = S;
		ans /= 2;
		ans *= mint(2).pow(n);
	}
	else{
		queue<vector<mint>> Q;
		rep(i,n){
			int t = 10000 - a[i];
			vector<mint> x(t+1,0);
			x[0] = 1;
			x.back() = 1;
			Q.push(x);
		}
		while(Q.size()>=2){
			auto x = Q.front();
			Q.pop();
			auto y = Q.front();
			Q.pop();
			Q.push(convolution(x,y));
		}
		rep(i,Q.front().size()){
			int D = 1000000000 - i;
			D %= M;
			ans += Q.front()[i] * D;
		}
	}
	cout<<ans.val()<<endl;
		
    return 0;
}
0