結果
問題 | No.1645 AB's abs |
ユーザー | srjywrdnprkt |
提出日時 | 2023-06-08 00:24:49 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 20 ms / 2,000 ms |
コード長 | 2,222 bytes |
コンパイル時間 | 1,072 ms |
コンパイル使用メモリ | 112,052 KB |
実行使用メモリ | 19,672 KB |
最終ジャッジ日時 | 2023-08-28 19:42:09 |
合計ジャッジ時間 | 3,559 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 2 ms
4,380 KB |
testcase_02 | AC | 8 ms
8,240 KB |
testcase_03 | AC | 2 ms
4,376 KB |
testcase_04 | AC | 2 ms
4,376 KB |
testcase_05 | AC | 2 ms
4,376 KB |
testcase_06 | AC | 3 ms
4,636 KB |
testcase_07 | AC | 2 ms
4,376 KB |
testcase_08 | AC | 8 ms
9,904 KB |
testcase_09 | AC | 8 ms
9,780 KB |
testcase_10 | AC | 8 ms
8,844 KB |
testcase_11 | AC | 7 ms
8,924 KB |
testcase_12 | AC | 8 ms
9,072 KB |
testcase_13 | AC | 19 ms
19,132 KB |
testcase_14 | AC | 18 ms
18,232 KB |
testcase_15 | AC | 19 ms
19,436 KB |
testcase_16 | AC | 18 ms
18,484 KB |
testcase_17 | AC | 19 ms
19,024 KB |
testcase_18 | AC | 19 ms
18,348 KB |
testcase_19 | AC | 20 ms
19,396 KB |
testcase_20 | AC | 17 ms
17,760 KB |
testcase_21 | AC | 18 ms
18,452 KB |
testcase_22 | AC | 19 ms
19,164 KB |
testcase_23 | AC | 19 ms
19,400 KB |
testcase_24 | AC | 19 ms
19,556 KB |
testcase_25 | AC | 20 ms
19,396 KB |
testcase_26 | AC | 19 ms
19,392 KB |
testcase_27 | AC | 19 ms
19,364 KB |
testcase_28 | AC | 19 ms
19,396 KB |
testcase_29 | AC | 19 ms
19,396 KB |
testcase_30 | AC | 19 ms
19,368 KB |
testcase_31 | AC | 20 ms
19,464 KB |
testcase_32 | AC | 19 ms
19,488 KB |
testcase_33 | AC | 18 ms
19,404 KB |
testcase_34 | AC | 19 ms
19,468 KB |
testcase_35 | AC | 19 ms
19,396 KB |
testcase_36 | AC | 19 ms
19,364 KB |
testcase_37 | AC | 19 ms
19,420 KB |
testcase_38 | AC | 19 ms
19,672 KB |
ソースコード
#include <iostream> #include <vector> #include <cmath> #include <map> #include <set> #include <iomanip> #include <queue> #include <algorithm> #include <numeric> #include <deque> #include <complex> #include <cassert> using namespace std; using ll = long long; const ll modc = 998244353; class mint { ll x; public: mint(ll x=0) : x((x%modc+modc)%modc) {} mint operator-() const { return mint(-x); } mint& operator+=(const mint& a) { if ((x += a.x) >= modc) x -= modc; return *this; } mint& operator-=(const mint& a) { if ((x += modc-a.x) >= modc) x -= modc; return *this; } mint& operator*=(const mint& a) { (x *= a.x) %= modc; return *this; } mint operator+(const mint& a) const { mint res(*this); return res+=a; } mint operator-(const mint& a) const { mint res(*this); return res-=a; } mint operator*(const mint& a) const { mint res(*this); return res*=a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; } mint inv() const { return pow(modc-2); } mint& operator/=(const mint& a) { return (*this) *= a.inv(); } mint operator/(const mint& a) const { mint res(*this); return res/=a; } bool operator == (const mint& a) const{ return x == a.x; } friend ostream& operator<<(ostream& os, const mint& m){ os << m.x; return os; } friend istream& operator>>(istream& ip, mint &m) { ll t; ip >> t; m = mint(t); return ip; } }; int main(){ int N; cin >> N; vector<int> A(N); for (int i=0; i<N; i++) cin >> A[i]; vector<vector<mint>> dp(N+1, vector<mint>(20001)); dp[0][10000] = 1; mint ans=0; for (int i=1; i<=N; i++){ for (int j=0; j<=20000; j++){ if (j-A[i-1] >= 0) dp[i][j] += dp[i-1][j-A[i-1]]; if (j+A[i-1] <= 20000) dp[i][j] += dp[i-1][j+A[i-1]]; } } for (int i=0; i<=20000; i++) ans += dp[N][i] * abs(i-10000); cout << ans << endl; }