結果

問題 No.1645 AB's abs
ユーザー inksamuraiinksamurai
提出日時 2021-08-13 21:34:52
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 2,307 bytes
コンパイル時間 1,156 ms
コンパイル使用メモリ 109,132 KB
実行使用メモリ 55,936 KB
最終ジャッジ日時 2024-04-14 16:57:27
合計ジャッジ時間 3,848 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,812 KB
testcase_01 AC 4 ms
6,812 KB
testcase_02 AC 17 ms
19,712 KB
testcase_03 AC 4 ms
6,944 KB
testcase_04 AC 4 ms
6,940 KB
testcase_05 AC 5 ms
6,940 KB
testcase_06 AC 7 ms
8,320 KB
testcase_07 AC 5 ms
6,944 KB
testcase_08 AC 22 ms
24,448 KB
testcase_09 AC 21 ms
24,448 KB
testcase_10 AC 19 ms
22,272 KB
testcase_11 AC 20 ms
22,272 KB
testcase_12 AC 19 ms
22,656 KB
testcase_13 AC 48 ms
54,784 KB
testcase_14 AC 47 ms
51,584 KB
testcase_15 AC 49 ms
54,656 KB
testcase_16 AC 47 ms
52,608 KB
testcase_17 AC 47 ms
54,144 KB
testcase_18 AC 46 ms
52,096 KB
testcase_19 AC 47 ms
54,656 KB
testcase_20 AC 44 ms
50,560 KB
testcase_21 AC 46 ms
52,608 KB
testcase_22 AC 47 ms
54,272 KB
testcase_23 AC 49 ms
55,680 KB
testcase_24 AC 48 ms
55,680 KB
testcase_25 AC 48 ms
55,680 KB
testcase_26 AC 49 ms
55,808 KB
testcase_27 AC 49 ms
55,680 KB
testcase_28 AC 49 ms
55,808 KB
testcase_29 AC 49 ms
55,808 KB
testcase_30 AC 49 ms
55,936 KB
testcase_31 AC 49 ms
55,680 KB
testcase_32 AC 49 ms
55,680 KB
testcase_33 AC 49 ms
55,808 KB
testcase_34 AC 49 ms
55,808 KB
testcase_35 AC 50 ms
55,680 KB
testcase_36 AC 49 ms
55,680 KB
testcase_37 AC 49 ms
55,680 KB
testcase_38 AC 49 ms
55,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <tuple>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <functional>
#include <numeric>
#include <iomanip> 
#include <stdio.h>
#include <assert.h>
#include <cstring>
//eolibraries
#define lnf 3999999999999999999
#define inf 999999999
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ld long double
#define all(c) (c).begin(),(c).end()
#define sz(c) (int)(c).size()
#define make_unique(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define pii pair <int,int>
#define rep(i,n) for(int i = 0 ; i < n ; i++) 
#define drep(i,n) for(int i = n-1 ; i >= 0 ; i--)
#define crep(i,x,n) for(int i = x ; i < n ; i++)
#define vi vector <int> 
#define vec(...) vector<__VA_ARGS__>
#define _3yHSMG9 ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
//eodefine
using namespace std;

const int mxn=22000;

//snuke's modular int
template <ll mod>
struct modularint{
	ll x;
	modularint(ll x=0):x(x%mod){}
	modularint& operator+=(const modularint a){
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	modularint& operator-=(const modularint a){
		if ((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	modularint& operator*=(const modularint a){
		(x *= a.x) %= mod;
		return *this;
	}
	modularint operator+(const modularint a)const{
		modularint res(*this);
		return res+=a;
	}
	modularint operator-(const modularint a)const{
		modularint res(*this);
		return res-=a;
	}
	modularint operator*(const modularint a)const{
		modularint res(*this);
		return res*=a;
	}
	modularint pow(ll n)const{
		modularint res=1,x(*this);
		while(n){
			if(n&1)res*=x;
			x*=x;
			n>>=1;
		}
		return res;
	}
	modularint inv()const{
		return pow(mod-2);
	}
};
using mint=modularint<998244353>;

int main(){
_3yHSMG9;
	int n;
	cin>>n;
	vi a(n);
	rep(i,n) cin>>a[i];
	vec(vec(mint)) dp(n+1,vec(mint)(3*mxn,0));
	dp[0][mxn]=1;
	rep(i,n){
		rep(s,2*mxn){
			if(dp[i][s].x==0) continue;
			dp[i+1][s+a[i]]+=dp[i][s];
			dp[i+1][s-a[i]]+=dp[i][s];
		}
	}
	mint ans=0;
	rep(s,2*mxn){
		ans+=dp[n][s]*abs(s-mxn);
	}
	cout<<ans.x<<"\n";
//	
	return 0;
}
0