結果

問題 No.1645 AB's abs
ユーザー ytsmash
提出日時 2021-08-14 14:48:22
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
RE  
実行時間 -
コード長 1,001 bytes
コンパイル時間 2,260 ms
コンパイル使用メモリ 196,216 KB
最終ジャッジ日時 2025-01-23 22:04:16
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample RE * 3
other RE * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 *    author:  ytsmash
 *    created: 14.08.2021 13:34:43
 **/

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) x.begin(), x.end()
const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
using P = pair<int, int>;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) {
        cin >> A[i];
    }
    /**
     * dp[i][j]は
     * A_1 ~ A_i までを用いて、
     * 総和が j になるときのBの場合の数
     */
    vector<vector<int>> dp(110, vector<int>(10010));
    dp[0][0] = 1;
    rep(i, N) {
        for (int j = -10000; j < 10001; j++) {
            dp[i + 1][j + A[i]] = dp[i][j];
            dp[i + 1][j - A[i]] = dp[i][j];
        }
    }

    ll ans = 0;
    const ll MOD = 998244353;

    for (int j = -10000; j < 10001; j++) {
        ans += abs(dp[N][j] * j);
        ans %= MOD;
    }
    cout << ans << "\n";
    return 0;
}
0