結果
問題 | No.1645 AB's abs |
ユーザー |
![]() |
提出日時 | 2021-08-13 21:54:42 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 17 ms / 2,000 ms |
コード長 | 1,927 bytes |
コンパイル時間 | 1,770 ms |
コンパイル使用メモリ | 171,900 KB |
実行使用メモリ | 11,136 KB |
最終ジャッジ日時 | 2024-10-03 18:37:49 |
合計ジャッジ時間 | 3,089 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
ソースコード
/*-------------- | /| | /| | /| * |/ | | ------ *| | | | / \| | |\ | | | |\ |\ | | | \ | | | | \ |\ | | | \ | | \ / \ |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() { EmiliaMyWifeint 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';}