結果

問題 No.1645 AB's abs
ユーザー tabae326tabae326
提出日時 2021-08-13 21:37:08
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 781 bytes
コンパイル時間 2,822 ms
コンパイル使用メモリ 204,548 KB
実行使用メモリ 11,392 KB
最終ジャッジ日時 2024-04-14 17:06:52
合計ジャッジ時間 3,780 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

#include <atcoder/modint>
using mint = atcoder::modint998244353;

void solve() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, 0, n) cin >> a[i];
    vector dp(n+1, vector<mint>(20010, 0));    
    ll offset = 10000;
    dp[0][offset] = 1;
    rep(i, 0, n) {
        rep(j, 0, 20010) {
            if(j-a[i] >= 0) dp[i+1][j-a[i]] += dp[i][j];
            if(j+a[i] < 20010) dp[i+1][j+a[i]] += dp[i][j];
        }
    }
    mint ans = 0;
    rep(i, 0, 20010) ans += abs(i - offset) * dp[n][i];
    cout << ans.val() << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}
0