結果

問題 No.1645 AB's abs
ユーザー ytsmash
提出日時 2021-08-14 15:09:26
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
RE  
実行時間 -
コード長 1,088 bytes
コンパイル時間 2,363 ms
コンパイル使用メモリ 199,068 KB
最終ジャッジ日時 2025-01-23 22:04:37
ジャッジサーバー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;
    const ll MOD = 998244353;
    vector<int> A(N);
    rep(i, N) { cin >> A[i]; }
    /**
     * dp[i][j]は
     * A_1 ~ A_i までを用いて、
     * 総和が j - 10000 になるときのBの場合の数
     */
    vector<vector<ll>> dp(110, vector<ll>(21000));
    dp[0][0] = 1;
    rep(i, N) {
        for (int j = 0; j <= 20000; j++) {
            dp[i + 1][j - A[i]] = dp[i][j];
            dp[i + 1][j - A[i]] %= MOD;
            dp[i + 1][j + A[i]] = dp[i][j];
            dp[i + 1][j + A[i]] %= MOD;
            
        }
    }

    ll ans = 0;

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