結果

問題 No.1645 AB's abs
ユーザー lolklolk
提出日時 2021-08-18 12:32:14
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 1,671 bytes
コンパイル時間 1,461 ms
コンパイル使用メモリ 129,304 KB
実行使用メモリ 20,992 KB
最終ジャッジ日時 2024-04-19 20:34:35
合計ジャッジ時間 3,617 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 5 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 7 ms
5,376 KB
testcase_09 AC 7 ms
5,376 KB
testcase_10 AC 6 ms
5,376 KB
testcase_11 AC 8 ms
5,376 KB
testcase_12 AC 7 ms
5,376 KB
testcase_13 AC 42 ms
13,952 KB
testcase_14 AC 28 ms
10,752 KB
testcase_15 AC 44 ms
14,464 KB
testcase_16 AC 41 ms
13,696 KB
testcase_17 AC 41 ms
13,824 KB
testcase_18 AC 34 ms
12,416 KB
testcase_19 AC 39 ms
13,440 KB
testcase_20 AC 31 ms
11,264 KB
testcase_21 AC 35 ms
12,416 KB
testcase_22 AC 40 ms
13,824 KB
testcase_23 AC 37 ms
13,184 KB
testcase_24 AC 39 ms
13,824 KB
testcase_25 AC 43 ms
14,464 KB
testcase_26 AC 38 ms
13,440 KB
testcase_27 AC 41 ms
14,336 KB
testcase_28 AC 39 ms
13,696 KB
testcase_29 AC 41 ms
13,952 KB
testcase_30 AC 46 ms
15,104 KB
testcase_31 AC 47 ms
14,464 KB
testcase_32 AC 46 ms
15,104 KB
testcase_33 AC 75 ms
20,736 KB
testcase_34 AC 77 ms
20,864 KB
testcase_35 AC 77 ms
20,992 KB
testcase_36 AC 76 ms
20,992 KB
testcase_37 AC 77 ms
20,992 KB
testcase_38 AC 3 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define all(v) (v).begin(), (v).end()
#define rep(i, j) for (ll i = 0; i < j; ++i)
#define rep2(i, j, k) for (ll i = j; i <= k; ++i)
#define rep3(i, j, k) for (ll i = j; i >= k; --i)

using namespace std;

using ld = long double;
using ll = long long;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vvpi = vector<vpi>;
using vvpl = vector<vpl>;

template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
template <class S, class T> inline bool chmax(S& x, T y) { if (x < y) { x = y; return 1; } return 0; }
template <class S, class T> inline bool chmin(S& x, T y) { if (x > y) { x = y; return 1; } return 0; }

constexpr int INF = 1000000000;
constexpr int MAX = 5005;
constexpr int MOD = 998244353;
constexpr ll INFLL = 1000000000000000000;

int main(void) {
    int n;
    cin >> n;

    vi a(n);
    rep(i, n) cin >> a[i];

    unordered_map<int,ll> dp[n+1];
    dp[0][0] = 1;

    rep(i, n) {
        for (auto [key, val] : dp[i]) {
            dp[i+1][key + a[i]] += val;
            dp[i+1][key + a[i]] %= MOD;

            dp[i+1][key - a[i]] += val;
            dp[i+1][key - a[i]] %= MOD;
        }
    }

    ll ans = 0;
    for (auto [key, val] : dp[n]) {
        ans += abs(key) * val % MOD;
        ans %= MOD;
    }

    cout << ans << endl;

    return (0);
}
0