Naxocist

1783D

Mar 23rd, 2024
901
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.45 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void dbg_out() { cerr << endl; }
  5. template<typename Head, typename... Tail>
  6. void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
  7. #define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
  8.  
  9. template<typename S, typename T> S amax(S &a, const T &b) { if(b > a) a = b; return a; }
  10. template<typename S, typename T> S amin(S &a, const T &b) { if(b < a) a = b; return a; }
  11.  
  12. #define all(x) x.begin(), x.end()
  13. #define allrev(x) x.rbegin(), x.rend()
  14. #define pb emplace_back
  15. #define sz(x) (int) (x).size()
  16. #define ln '\n'
  17. using ll = long long;
  18. using pi = pair<ll, ll>;
  19. using T = tuple<ll, ll, ll>;
  20. const ll INF = 2e9;
  21. const int N = 303, mod = 998244353, z = 1e5;
  22.  
  23. void runcase() {
  24.     int n; cin >> n;
  25.     vector<int> v(n+1); for(int i=1; i<=n; ++i) cin >> v[i];
  26.  
  27.     vector<int> dp(3*z + 1);
  28.     dp[z + v[2]] = 1;
  29.     for(int i=1; i<=n-2; ++i) {
  30.         vector<int> nxt(3*z + 1);
  31.         for(int x=-z; x<=z; ++x) {
  32.             nxt[z+v[i+2]+x] += dp[z+x], nxt[z+v[i+2]+x]%=mod;
  33.             if(x!=0){
  34.                 nxt[z+v[i+2]-x] += dp[z+x], nxt[z+v[i+2]-x]%=mod;
  35.             }
  36.         }
  37.         dp = nxt;
  38.     }
  39.  
  40.     int res = 0;
  41.     for(int i=0; i<=2*z; ++i) res += dp[i], res%=mod;
  42.     cout << res << ln;
  43.     return ;
  44. }
  45.  
  46. int32_t main() {
  47.     cin.tie(nullptr)->sync_with_stdio(0);
  48.     int TC = 1;
  49.     // cin >> TC;
  50.     while(TC--) runcase();
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment