結果

問題 No.1645 AB's abs
ユーザー 👑 platinumplatinum
提出日時 2021-08-13 21:43:10
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 1,597 bytes
コンパイル時間 2,148 ms
コンパイル使用メモリ 196,112 KB
実行使用メモリ 38,152 KB
最終ジャッジ日時 2024-04-14 17:20:33
合計ジャッジ時間 3,828 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
38,004 KB
testcase_01 AC 11 ms
37,816 KB
testcase_02 AC 12 ms
37,820 KB
testcase_03 AC 11 ms
37,912 KB
testcase_04 AC 11 ms
38,152 KB
testcase_05 AC 11 ms
38,132 KB
testcase_06 AC 12 ms
37,956 KB
testcase_07 AC 11 ms
37,996 KB
testcase_08 AC 13 ms
37,944 KB
testcase_09 AC 12 ms
37,960 KB
testcase_10 AC 12 ms
37,852 KB
testcase_11 AC 12 ms
38,036 KB
testcase_12 AC 12 ms
37,900 KB
testcase_13 AC 14 ms
37,916 KB
testcase_14 AC 14 ms
38,064 KB
testcase_15 AC 15 ms
38,012 KB
testcase_16 AC 14 ms
38,008 KB
testcase_17 AC 15 ms
37,992 KB
testcase_18 AC 14 ms
37,820 KB
testcase_19 AC 14 ms
37,828 KB
testcase_20 AC 14 ms
37,808 KB
testcase_21 AC 14 ms
37,928 KB
testcase_22 AC 14 ms
37,928 KB
testcase_23 AC 15 ms
37,964 KB
testcase_24 AC 14 ms
37,800 KB
testcase_25 AC 14 ms
37,820 KB
testcase_26 AC 15 ms
37,932 KB
testcase_27 AC 14 ms
37,892 KB
testcase_28 AC 14 ms
37,876 KB
testcase_29 AC 14 ms
37,840 KB
testcase_30 AC 14 ms
37,952 KB
testcase_31 AC 15 ms
37,808 KB
testcase_32 AC 15 ms
37,988 KB
testcase_33 AC 15 ms
37,976 KB
testcase_34 AC 14 ms
37,864 KB
testcase_35 AC 14 ms
37,984 KB
testcase_36 AC 14 ms
38,032 KB
testcase_37 AC 15 ms
37,928 KB
testcase_38 AC 14 ms
37,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)

using namespace std;
using LL = long long;
using P = pair<int,int>;
using vv = vector<vector<int>>;
const int INF = (int)1e9;
const LL LINF = (LL)1e18;

long long const mod = 998244353;
struct mint{
	long long val;
	mint(long long val = 0): val(val % mod) {}
	mint& operator += (const mint n){
		val += n.val;
		if(val >= mod) val -= mod;
		return *this;
	}
	mint& operator -= (const mint n){
		val -= n.val;
		if(val < 0) val += mod;
		return *this;
	}
	mint& operator *= (const mint n){
		val *= n.val;
		val %= mod;
		if(val < 0) val += mod;
		return *this;
	}
	mint operator + (const mint n) const{
		mint res(*this);
		return res += n;
	}
	mint operator - (const mint n) const{
		mint res(*this);
		return res -= n;
	}
	mint operator * (const mint n) const{
		mint res(*this);
		return res *= n;
	}
	mint pow(long long n) const{
		if(n == 0) return 1;
		mint m = pow(n >> 1);
		m *= m;
		if(n & 1) m *= *this;
		return m;
	}
	// mint division for prime mod
	mint inv() const{
		return pow(mod - 2);
	}
	mint& operator /= (const mint n){
		return (*this) *= n.inv();
	}
	mint operator / (const mint n) const{
		mint res(*this);
		return res /= n;
	}
};

mint dp[110][40010];

int main(){
	int N;
	cin >> N;
	vector<int> A(N);
	rep(i,N) cin >> A[i];
	dp[0][20000] = 1;
	rep(i,N){
		for(int j = 10000; j <= 30000; j++){
			dp[i+1][j+A[i]] += dp[i][j];
			dp[i+1][j-A[i]] += dp[i][j];
		}
	}
	mint ans = 0;
	rep(j,40005){
		mint tot = abs(j - 20000);
		ans += tot * dp[N][j];
	}
	cout << ans.val << endl;

	return 0;
}
0