結果

問題 No.1645 AB's abs
ユーザー rk427454171rk427454171
提出日時 2021-08-13 21:54:42
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 1,927 bytes
コンパイル時間 1,869 ms
コンパイル使用メモリ 168,380 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-04-14 17:43:26
合計ジャッジ時間 3,364 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 3 ms
6,944 KB
testcase_10 AC 3 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 3 ms
6,940 KB
testcase_13 AC 8 ms
7,168 KB
testcase_14 AC 7 ms
6,944 KB
testcase_15 AC 9 ms
7,424 KB
testcase_16 AC 9 ms
7,168 KB
testcase_17 AC 10 ms
7,296 KB
testcase_18 AC 8 ms
6,940 KB
testcase_19 AC 9 ms
7,168 KB
testcase_20 AC 7 ms
6,940 KB
testcase_21 AC 8 ms
6,944 KB
testcase_22 AC 9 ms
7,424 KB
testcase_23 AC 9 ms
7,040 KB
testcase_24 AC 9 ms
7,296 KB
testcase_25 AC 9 ms
7,424 KB
testcase_26 AC 8 ms
7,040 KB
testcase_27 AC 10 ms
7,424 KB
testcase_28 AC 10 ms
7,296 KB
testcase_29 AC 9 ms
7,040 KB
testcase_30 AC 9 ms
7,808 KB
testcase_31 AC 9 ms
7,168 KB
testcase_32 AC 9 ms
7,424 KB
testcase_33 AC 15 ms
10,368 KB
testcase_34 AC 14 ms
10,368 KB
testcase_35 AC 15 ms
10,496 KB
testcase_36 AC 15 ms
10,496 KB
testcase_37 AC 16 ms
10,496 KB
testcase_38 AC 17 ms
11,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << "\e[1;31m" << #x << " = " << (x) << "\e[0m\n"
#define print(x) emilia_mata_tenshi(#x, begin(x), end(x))
template<typename T> void emilia_mata_tenshi(const char *s, T l, T r) {
	cerr << "\e[1;33m" << s << " = [";
	while(l != r) {
		cerr << *l;
		cerr << (++l == r ? ']' : ',');
	}
	cerr << "\e[0m\n";
}

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
using ll = int64_t;
using ull = uint64_t;
using ld = long double;
using uint = uint32_t;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
/*--------------------------------------------------------------------------------------*/

signed main() { EmiliaMyWife
	int n;
	cin >> n;
	vector<int> arr(n + 1);
	for(int i = 1; i <= n; i++)
		cin >> arr[i];
	int s = accumulate(arr.begin(), arr.end(), 0);
	vector<vector<int>> dp(n + 1, vector<int>(s * 2 + 1));
	dp[0][s] = 1;
	const int mod = 998244353;
	for(int i = 1; i <= n; i++) {
		for(int j = 0; j <= s * 2; j++) {
			if(j - arr[i] >= 0)
				dp[i][j] = (dp[i][j] + dp[i - 1][j - arr[i]]) % mod;
			if(j + arr[i] <= s * 2)
				dp[i][j] = (dp[i][j] + dp[i - 1][j + arr[i]]) % mod;
		}
	}
	ll ans = 0;
	//print(dp[n]);
	for(int i = 0; i <= s * 2; i++)
		ans = (ans + 1LL * dp[n][i] * abs(i - s)) % mod;
	cout << ans << '\n';
}
0