結果

問題 No.1645 AB's abs
ユーザー tnakao0123tnakao0123
提出日時 2021-08-14 21:43:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 1,243 bytes
コンパイル時間 756 ms
コンパイル使用メモリ 93,440 KB
実行使用メモリ 8,064 KB
最終ジャッジ日時 2024-04-15 19:16:11
合計ジャッジ時間 1,936 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 5 ms
6,272 KB
testcase_14 AC 4 ms
5,632 KB
testcase_15 AC 5 ms
6,272 KB
testcase_16 AC 6 ms
6,144 KB
testcase_17 AC 5 ms
6,144 KB
testcase_18 AC 5 ms
5,888 KB
testcase_19 AC 5 ms
6,016 KB
testcase_20 AC 4 ms
5,504 KB
testcase_21 AC 5 ms
6,016 KB
testcase_22 AC 5 ms
6,144 KB
testcase_23 AC 5 ms
6,144 KB
testcase_24 AC 5 ms
6,272 KB
testcase_25 AC 5 ms
6,400 KB
testcase_26 AC 5 ms
6,144 KB
testcase_27 AC 5 ms
6,272 KB
testcase_28 AC 5 ms
6,272 KB
testcase_29 AC 5 ms
6,016 KB
testcase_30 AC 6 ms
6,144 KB
testcase_31 AC 6 ms
6,144 KB
testcase_32 AC 5 ms
6,272 KB
testcase_33 AC 7 ms
7,680 KB
testcase_34 AC 8 ms
7,680 KB
testcase_35 AC 7 ms
7,808 KB
testcase_36 AC 8 ms
7,808 KB
testcase_37 AC 8 ms
7,680 KB
testcase_38 AC 8 ms
8,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1645.cc:  No.1645 AB's abs - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;
const int MAX_A = 100;
const int MAX_S = MAX_N * MAX_A;
const int MOD = 998244353;

/* typedef */

typedef long long ll;

/* global variables */

int as[MAX_N], dp[MAX_N + 1][MAX_S * 2 + 1];

/* subroutines */

inline void addmod(int &a, int b) { a = (a + b) % MOD; }

/* main */

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", as + i);

  dp[0][MAX_S] = 1;
  int minj = MAX_S, maxj = MAX_S;

  for (int i = 0; i < n; i++) {
    for (int j = minj; j <= maxj; j++) {
      addmod(dp[i + 1][j + as[i]], dp[i][j]);
      addmod(dp[i + 1][j - as[i]], dp[i][j]);
    }
    minj -= as[i], maxj += as[i];
  }

  int sum = 0;
  for (int j = MAX_S; j <= maxj; j++)
    addmod(sum, (ll)(j - MAX_S) * dp[n][j] % MOD);

  printf("%d\n", (sum * 2) % MOD);
  return 0;
}
0