結果

問題 No.2062 Sum of Subset mod 999630629
ユーザー okkuukenkenokkuukenken
提出日時 2022-08-26 22:28:29
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 955 bytes
コンパイル時間 1,942 ms
コンパイル使用メモリ 166,860 KB
実行使用メモリ 22,400 KB
最終ジャッジ日時 2024-04-22 00:33:51
合計ジャッジ時間 8,383 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 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 1 ms
5,376 KB
testcase_08 AC 32 ms
5,376 KB
testcase_09 AC 28 ms
5,376 KB
testcase_10 AC 25 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 #

#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<iomanip>
#include<numeric>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<random>
#include<bitset>
#include<cassert>
#include<complex>
#include<fstream>
#include<cstdlib>
#include<functional>
#include<array>
using namespace std;
typedef long long ll;
const int mod=998244353;
const int dx[]={1,0,0,-1},dy[]={0,1,-1,0};
int n,a[200000],sum[200001],pow2[200000];
map<pair<int,int>,int>mp;
int rec(int i,int s){
	if(s>sum[i])
		return 0;
	if(s<=0)
		return pow2[i];
	if(i==0)
		return 0;
	return mp[{i,s}]=rec(i-1,s)+rec(i-1,s-a[i-1]);
}
int main(){
	cin>>n;
	pow2[0]=1;
	for(int i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<n;i++){
		sum[i+1]=sum[i]+a[i];
		pow2[i+1]=pow2[i]*2%mod;
	}
	int ans=(ll)pow2[n-1]*sum[n]%mod;
	ans=(ans+996858077ll*rec(n,999630629))%mod;
	cout<<ans<<endl;
}
0