結果
問題 | No.1645 AB's abs |
ユーザー |
![]() |
提出日時 | 2021-08-13 21:37:08 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 18 ms / 2,000 ms |
コード長 | 781 bytes |
コンパイル時間 | 2,623 ms |
コンパイル使用メモリ | 199,820 KB |
最終ジャッジ日時 | 2025-01-23 18:28:07 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++) #include <atcoder/modint> using mint = atcoder::modint998244353; void solve() { ll n; cin >> n; vector<ll> a(n); rep(i, 0, n) cin >> a[i]; vector dp(n+1, vector<mint>(20010, 0)); ll offset = 10000; dp[0][offset] = 1; rep(i, 0, n) { rep(j, 0, 20010) { if(j-a[i] >= 0) dp[i+1][j-a[i]] += dp[i][j]; if(j+a[i] < 20010) dp[i+1][j+a[i]] += dp[i][j]; } } mint ans = 0; rep(i, 0, 20010) ans += abs(i - offset) * dp[n][i]; cout << ans.val() << endl; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); solve(); return 0; }