結果

問題 No.1645 AB's abs
ユーザー lolklolk
提出日時 2021-08-18 12:31:26
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 170 ms / 2,000 ms
コード長 1,661 bytes
コンパイル時間 1,397 ms
コンパイル使用メモリ 129,144 KB
実行使用メモリ 29,312 KB
最終ジャッジ日時 2024-04-19 20:33:56
合計ジャッジ時間 5,020 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 6 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 10 ms
6,944 KB
testcase_09 AC 11 ms
6,944 KB
testcase_10 AC 7 ms
6,940 KB
testcase_11 AC 10 ms
6,944 KB
testcase_12 AC 9 ms
6,944 KB
testcase_13 AC 82 ms
19,200 KB
testcase_14 AC 50 ms
14,080 KB
testcase_15 AC 82 ms
19,328 KB
testcase_16 AC 80 ms
18,688 KB
testcase_17 AC 77 ms
18,816 KB
testcase_18 AC 66 ms
16,768 KB
testcase_19 AC 78 ms
18,432 KB
testcase_20 AC 57 ms
14,976 KB
testcase_21 AC 67 ms
16,768 KB
testcase_22 AC 83 ms
18,688 KB
testcase_23 AC 85 ms
17,792 KB
testcase_24 AC 88 ms
18,944 KB
testcase_25 AC 94 ms
19,584 KB
testcase_26 AC 84 ms
18,176 KB
testcase_27 AC 96 ms
19,328 KB
testcase_28 AC 88 ms
18,944 KB
testcase_29 AC 89 ms
18,944 KB
testcase_30 AC 102 ms
20,480 KB
testcase_31 AC 97 ms
19,968 KB
testcase_32 AC 98 ms
20,352 KB
testcase_33 AC 165 ms
28,928 KB
testcase_34 AC 166 ms
29,184 KB
testcase_35 AC 170 ms
29,312 KB
testcase_36 AC 165 ms
29,056 KB
testcase_37 AC 166 ms
29,312 KB
testcase_38 AC 2 ms
6,940 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];

    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