結果

問題 No.1645 AB's abs
ユーザー karinohito
提出日時 2021-08-13 21:41:55
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 708 bytes
コンパイル時間 1,678 ms
コンパイル使用メモリ 173,244 KB
実行使用メモリ 35,456 KB
最終ジャッジ日時 2024-10-03 18:02:20
合計ジャッジ時間 3,687 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

//#include <atcoder/all>
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
//using namespace atcoder;
using ll = long long;
#define all(A) A.begin(),A.end()
using vll = vector<ll>;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using Graph = vector<vector<ll>>;



int main() {
	ll N;
	cin>>N;
	vll A(N);
	rep(i,N)cin>>A[i];
	vector<vll> DP(N+1,vll(40000,0));
	DP[0][20000]=1;
	ll mod=998244353;
	rep(i,N){
		rep(j,40000){
			if(DP[i][j]>0){
				DP[i+1][j+A[i]]+=DP[i][j];
				DP[i+1][j-A[i]]+=DP[i][j];
				DP[i+1][j+A[i]]%=mod;
				DP[i+1][j-A[i]]%=mod;
			}
		}
	}
	ll an=0;
	rep(i,40000){
		ll p=DP[N][i]*abs(i-20000);
		p%=mod;
		
		an+=p;
		an%=mod;
	}
	cout<<an<<endl;
}
0