結果

問題 No.1645 AB's abs
ユーザー rianoriano
提出日時 2021-08-13 21:32:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 2,598 bytes
コンパイル時間 1,620 ms
コンパイル使用メモリ 164,156 KB
実行使用メモリ 19,428 KB
最終ジャッジ日時 2024-04-14 16:52:07
合計ジャッジ時間 3,033 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 5 ms
8,216 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 3 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 6 ms
9,840 KB
testcase_09 AC 5 ms
9,744 KB
testcase_10 AC 5 ms
9,204 KB
testcase_11 AC 5 ms
8,980 KB
testcase_12 AC 5 ms
9,328 KB
testcase_13 AC 10 ms
18,892 KB
testcase_14 AC 10 ms
18,060 KB
testcase_15 AC 10 ms
18,924 KB
testcase_16 AC 11 ms
18,376 KB
testcase_17 AC 10 ms
18,904 KB
testcase_18 AC 10 ms
18,276 KB
testcase_19 AC 10 ms
18,928 KB
testcase_20 AC 9 ms
17,680 KB
testcase_21 AC 9 ms
18,276 KB
testcase_22 AC 9 ms
18,804 KB
testcase_23 AC 12 ms
19,224 KB
testcase_24 AC 10 ms
19,284 KB
testcase_25 AC 11 ms
19,128 KB
testcase_26 AC 10 ms
19,380 KB
testcase_27 AC 11 ms
19,252 KB
testcase_28 AC 11 ms
19,372 KB
testcase_29 AC 11 ms
19,220 KB
testcase_30 AC 10 ms
19,272 KB
testcase_31 AC 10 ms
19,244 KB
testcase_32 AC 11 ms
19,428 KB
testcase_33 AC 11 ms
19,204 KB
testcase_34 AC 11 ms
19,384 KB
testcase_35 AC 11 ms
19,332 KB
testcase_36 AC 11 ms
19,292 KB
testcase_37 AC 11 ms
19,144 KB
testcase_38 AC 11 ms
19,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define Pr pair<ll,ll>
#define Tp tuple<int,int,int>
#define riano_ std::ios::sync_with_stdio(false);std::cin.tie(nullptr);typedef modint<mod> mint
using Graph = vector<vector<int>>;

const ll mod = 998244353;
template<uint64_t mod>
struct modint{
    uint64_t val;
    constexpr modint(const int64_t val_=0) noexcept:val((val_%int64_t(mod)+int64_t(mod))%int64_t(mod)){}
    constexpr modint operator-() const noexcept{
        return modint(*this)=mod-val;
    }
    constexpr modint operator+(const modint rhs) const noexcept{
        return modint(*this)+=rhs;
    }
    constexpr modint operator-(const modint rhs) const noexcept{
        return modint(*this)-=rhs;
    }
    constexpr modint operator*(const modint rhs) const noexcept{
        return modint(*this)*=rhs;
    }
    constexpr modint operator/(const modint rhs) const noexcept{
        return modint(*this)/=rhs;
    }
    constexpr modint &operator+=(const modint rhs) noexcept{
        val+=rhs.val;
        val-=((val>=mod)?mod:0);
        return (*this);
    }
    constexpr modint &operator-=(const modint rhs) noexcept{
        val+=((val<rhs.val)?mod:0);
        val-=rhs.val;
        return (*this);
    }
    constexpr modint &operator*=(const modint rhs) noexcept{
        val=val*rhs.val%mod;
        return (*this);
    }
    constexpr modint &operator/=(modint rhs) noexcept{
        uint64_t ex=mod-2;
        modint now=1;
        while(ex){
            now*=((ex&1)?rhs:1);
            rhs*=rhs,ex>>=1;
        }
        return (*this)*=now;
    }
    constexpr bool operator==(const modint rhs) noexcept{
        return val==rhs.val;
    }
    constexpr bool operator!=(const modint rhs) noexcept{
        return val!=rhs.val;
    }
    friend constexpr ostream &operator<<(ostream& os,const modint x) noexcept{
        return os<<(x.val);
    }
    friend constexpr istream &operator>>(istream& is,modint& x) noexcept{
        uint64_t t;
        is>>t,x=t;
        return is;
    }
};

int main() {
    riano_;
    //ll N; cin >> N; ll ans = 0;
    ll N; cin >> N;
    ll a[N];
    rep(i,N) cin >> a[i];
    mint ans = 0;
    mint dp[N+1][20001];
    rep(i,N+1){
        rep(j,20001) dp[i][j] = 0;
    }
    dp[0][10000] = 1;
    rep(i,N){
        rep(j,20001){
            if(dp[i][j]==0) continue;
            dp[i+1][j+a[i]] += dp[i][j];
            dp[i+1][j-a[i]] += dp[i][j];
        }
    }
    rep(i,20001){
        ans += dp[N][i]*mint(abs(i-10000));
    }
    
    cout << ans << endl;
}
0