結果
問題 |
No.1645 AB's abs
|
ユーザー |
|
提出日時 | 2022-08-29 22:41:00 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 23 ms / 2,000 ms |
コード長 | 805 bytes |
コンパイル時間 | 2,222 ms |
コンパイル使用メモリ | 198,644 KB |
最終ジャッジ日時 | 2025-02-06 23:40:01 |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
ソースコード
typedef long long ll; typedef long double ld; #include <bits/stdc++.h> using namespace std; #define int long long const ll MOD = 998244353; signed main(){ ll n; std::cin >> n; vector<ll> a(n); for (int i = 0; i < n; i++) { std::cin >> a[i]; } vector<vector<ll>> dp(n+1,vector<ll>(20010)); dp[0][10000] = 1; for (int i = 0; i < n; i++) { for (int j = -10000; j <= 10000; j++) { if(j+10000-a[i]>=0)dp[i+1][j+10000] += dp[i][j+10000-a[i]]; if(j+10000+a[i]<=20000)dp[i+1][j+10000] += dp[i][j+10000+a[i]]; dp[i+1][j+10000]%=MOD; } } ll ans = 0; for (int i = -10000; i <= 10000; i++) { ans += (abs(i)+MOD)%MOD*dp[n][i+10000]%MOD; ans %= MOD; } std::cout << ans << std::endl; }