結果

問題 No.1645 AB's abs
ユーザー kuc_jacksonkuc_jackson
提出日時 2021-08-14 01:44:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 817 bytes
コンパイル時間 2,246 ms
コンパイル使用メモリ 200,752 KB
実行使用メモリ 27,392 KB
最終ジャッジ日時 2024-04-14 23:21:17
合計ジャッジ時間 4,255 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 3 ms
6,944 KB
testcase_02 AC 8 ms
10,752 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 3 ms
6,940 KB
testcase_06 AC 4 ms
6,940 KB
testcase_07 AC 3 ms
6,944 KB
testcase_08 AC 11 ms
12,928 KB
testcase_09 AC 11 ms
12,928 KB
testcase_10 AC 10 ms
11,904 KB
testcase_11 AC 10 ms
11,904 KB
testcase_12 AC 10 ms
12,160 KB
testcase_13 AC 23 ms
26,752 KB
testcase_14 AC 22 ms
25,472 KB
testcase_15 AC 24 ms
26,880 KB
testcase_16 AC 23 ms
25,856 KB
testcase_17 AC 24 ms
26,624 KB
testcase_18 AC 22 ms
25,600 KB
testcase_19 AC 24 ms
26,752 KB
testcase_20 AC 22 ms
25,088 KB
testcase_21 AC 23 ms
25,856 KB
testcase_22 AC 23 ms
26,624 KB
testcase_23 AC 24 ms
27,392 KB
testcase_24 AC 24 ms
27,264 KB
testcase_25 AC 25 ms
27,264 KB
testcase_26 AC 25 ms
27,264 KB
testcase_27 AC 24 ms
27,264 KB
testcase_28 AC 24 ms
27,392 KB
testcase_29 AC 24 ms
27,264 KB
testcase_30 AC 25 ms
27,264 KB
testcase_31 AC 24 ms
27,264 KB
testcase_32 AC 24 ms
27,264 KB
testcase_33 AC 25 ms
27,392 KB
testcase_34 AC 25 ms
27,392 KB
testcase_35 AC 25 ms
27,392 KB
testcase_36 AC 25 ms
27,392 KB
testcase_37 AC 24 ms
27,264 KB
testcase_38 AC 24 ms
27,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

int main(){
    const ll mod = 998244353;
    int N; cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++)cin >> A[i];
    vector<vector<ll>> dp(N + 1, vector<ll>(30000));
    ll stan = 15000;
    dp[1][stan + A[0]] = 1;
    dp[1][stan - A[0]] = 1;
    for(int i = 1; i < N; i++){
        for(int j = 4990; j <= 25010; j++){
            if(!dp[i][j])continue;
            dp[i + 1][j + A[i]] = (dp[i + 1][j + A[i]] + dp[i][j]) % mod;
            dp[i + 1][j - A[i]] = (dp[i + 1][j - A[i]] + dp[i][j]) % mod;
        }
    }
    ll ans = 0;
    for(ll n = 4990; n <= 25010; n++){
        if(dp[N][n])ans = (ans + (dp[N][n] * abs(n - stan)) % mod) % mod;
    }
    cout << ans << endl;
}
0