結果

問題 No.2062 Sum of Subset mod 999630629
ユーザー tamatotamato
提出日時 2022-08-26 23:14:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,841 bytes
コンパイル時間 4,800 ms
コンパイル使用メモリ 261,892 KB
実行使用メモリ 9,600 KB
最終ジャッジ日時 2024-04-22 01:20:22
合計ジャッジ時間 7,457 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 11 ms
6,940 KB
testcase_09 AC 9 ms
6,944 KB
testcase_10 AC 9 ms
6,940 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 9 ms
6,944 KB
testcase_24 AC 8 ms
6,940 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
//#define _GLIBCXX_DEBUG
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using namespace atcoder;
using ll = long long;
using pll = pair<ll, ll>;
using pii = pair<int, int>;

long long pow(long long x, long long n, ll mod) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret *= x;  // n の最下位bitが 1 ならば x^(2^i) をかける
        ret %= mod;
        x *= x;
        x %= mod;
        n >>= 1;  // n を1bit 左にずらす
    }
    return ret;
}


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll mod = 998244353;
  ll mod2 = 999630629;
  int N; cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A[i];

  ll ans = 0;
  ll pow2 = pow(2, N - 1, mod);
  rep(i, N) {
    ans = (ans + (pow2 * A[i]) % mod) % mod;
  }

  ll D = -mod2;
  rep(i, N) {
    D += A[i];
  }

  if (D >= 0) {
    vector<int> cnt(10000 + 1);
    rep(i, N) {
      cnt[A[i]]++;
    }

    vector<ll> dp(D + 1);
    dp[0] = 1;
    rep(i_, 10000) {
      int i = i_ + 1;
      if (cnt[i] == 0) continue;
      vector<int> K(0);
      int j = 0;
      while (true) {
        if (cnt[i] < (1 << j)) break;
        K.push_back(1 << j);
        cnt[i] -= (1 << j);
        j++;
      }
      if (cnt[i] > 0) K.push_back(cnt[i]);
      for (auto k: K) {
        ll ak = A[i] * k;
        if (ak > D) continue;
        vector<ll> dp_new(D + 1);
        rep(j, D + 1) {
          dp_new[j] = (dp_new[j] + dp[j])%mod;
          if (j + ak <= D) {
            dp_new[j + ak] = (dp_new[j + ak] + dp[j])%mod;
          }
        }
        dp = dp_new;
      }

    }
    rep(i, D + 1) {
      ans = (ans - (mod2 * dp[i])%mod) % mod;
    }
  }
  
  cout << ans << endl;

}

0