結果

問題 No.1645 AB's abs
ユーザー nawawannawawan
提出日時 2021-08-13 21:34:23
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 2,612 bytes
コンパイル時間 2,089 ms
コンパイル使用メモリ 201,728 KB
実行使用メモリ 27,392 KB
最終ジャッジ日時 2024-04-14 16:55:54
合計ジャッジ時間 3,855 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 3 ms
6,940 KB
testcase_02 AC 9 ms
10,624 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 3 ms
6,940 KB
testcase_05 AC 3 ms
6,940 KB
testcase_06 AC 4 ms
6,944 KB
testcase_07 AC 3 ms
6,940 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 9 ms
12,032 KB
testcase_12 AC 10 ms
12,160 KB
testcase_13 AC 24 ms
26,752 KB
testcase_14 AC 22 ms
25,472 KB
testcase_15 AC 24 ms
26,752 KB
testcase_16 AC 23 ms
25,856 KB
testcase_17 AC 24 ms
26,624 KB
testcase_18 AC 23 ms
25,600 KB
testcase_19 AC 24 ms
26,752 KB
testcase_20 AC 22 ms
24,960 KB
testcase_21 AC 24 ms
25,856 KB
testcase_22 AC 24 ms
26,880 KB
testcase_23 AC 24 ms
27,264 KB
testcase_24 AC 24 ms
27,264 KB
testcase_25 AC 24 ms
27,264 KB
testcase_26 AC 24 ms
27,264 KB
testcase_27 AC 25 ms
27,264 KB
testcase_28 AC 24 ms
27,264 KB
testcase_29 AC 24 ms
27,264 KB
testcase_30 AC 25 ms
27,392 KB
testcase_31 AC 24 ms
27,264 KB
testcase_32 AC 25 ms
27,264 KB
testcase_33 AC 25 ms
27,264 KB
testcase_34 AC 24 ms
27,264 KB
testcase_35 AC 25 ms
27,264 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;
template<const int MOD> struct modint{
    long long val;
    modint(): val(0) {}
    modint(long long x){
        if(x < 0) val = x % MOD + MOD;
        else val = x % MOD;
    }
    modint(const modint &t){
        val = t.val;
    }
    modint& operator =(const modint m){
        val = m.val;
        return *this;
    }
    modint operator -(){
        return modint(-val);
    }
    modint& operator-=(const modint &m){
        val -= m.val;
        if(val < 0) val += MOD;
        return *this;
    }
    modint& operator+=(const modint &m){
        val += m.val;
        if(val >= MOD) val -= MOD;
        return *this;
    }
    modint& operator*=(const modint &m){
        val *= m.val;
        val %= MOD;
        return *this;
    }
    modint& operator/=(modint m){
        *this *= m.inv();
        return *this;
    }
    modint inv(){
        long long x = 1, y = 0;
        long long a = val, b = MOD;
        while(b != 0){
            long long t = a / b;
            a -= t * b;
            x -= t * y;
            swap(a, b);
            swap(x, y);
        }
        x %= MOD;
        if(x < 0) x += MOD;
        return modint(x);
    }
    modint pow(long long k){
        long long res = 1;
        long long v = val;
        while(k > 0){
            if(k & 1) res = res * v % MOD;
            v = v * v % MOD;
            k >>= 1;
        }
        return modint(res);
    }
    bool operator==(const modint &m){
        return val == m.val;
    }
    modint operator+(const modint &m){
        return modint(*this) += m;
    }
    modint operator-(const modint &m){
        return modint(*this) -= m;
    }
    modint operator*(const modint &m){
        return modint(*this) *= m;
    }
    modint operator/(const modint &m){
        return modint(*this) /= m;
    }
    bool operator!=(const modint &m){
        return modint(*this).val != m.val;
    }
    bool operator!=(const int &m){
        return modint(*this).val != m;
    }
};
const int MOD = 998244353;
using mint = modint<MOD>;
int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    vector<vector<mint>> dp(N + 1, vector<mint>(30010));
    dp[0][15000] = 1;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < 30010; j++){
            if(dp[i][j].val != 0){
                dp[i + 1][j + A[i]] += dp[i][j];
                dp[i + 1][j - A[i]] += dp[i][j];
            }
        }
    }
    mint ans = 0;
    for(int i = 0; i < 30010; i++){
        ans += dp[N][i] * abs(i - 15000);
    }
    cout << ans.val << endl;
}
0