結果
問題 | No.1645 AB's abs |
ユーザー | riano |
提出日時 | 2021-08-13 21:32:38 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 17 ms / 2,000 ms |
コード長 | 2,598 bytes |
コンパイル時間 | 1,609 ms |
コンパイル使用メモリ | 167,192 KB |
実行使用メモリ | 19,308 KB |
最終ジャッジ日時 | 2024-10-03 17:25:31 |
合計ジャッジ時間 | 3,133 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
ソースコード
#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; }