結果
問題 | No.1645 AB's abs |
ユーザー |
![]() |
提出日時 | 2021-08-13 22:16:12 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 25 ms / 2,000 ms |
コード長 | 635 bytes |
コンパイル時間 | 625 ms |
コンパイル使用メモリ | 69,608 KB |
実行使用メモリ | 19,200 KB |
最終ジャッジ日時 | 2024-10-03 19:39:25 |
合計ジャッジ時間 | 2,714 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
ソースコード
#include <iostream>#include <cmath>#define int long long#define rep(i, n) for(i = 0; i < n; i++)using namespace std;const int C = 10000;const int mod = 998244353;int n;int a[100];int dp[101][2 * C + 1];signed main() {int i, j;cin >> n;rep(i, n) cin >> a[i];dp[0][C] = 1;rep(i, n) {rep(j, 2 * C + 1) {if (0 <= j + a[i] && j + a[i] <= 2 * C) (dp[i + 1][j + a[i]] += dp[i][j]) %= mod;if (0 <= j - a[i] && j - a[i] <= 2 * C) (dp[i + 1][j - a[i]] += dp[i][j]) %= mod;}}int ans = 0;rep(j, 2 * C + 1) {ans += abs(j - C) * dp[n][j] % mod;ans %= mod;}cout << ans << endl;return 0;}