結果

問題 No.1645 AB's abs
ユーザー monnumonnu
提出日時 2021-08-19 22:48:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 751 bytes
コンパイル時間 3,696 ms
コンパイル使用メモリ 225,528 KB
実行使用メモリ 19,840 KB
最終ジャッジ日時 2024-04-21 02:13:11
合計ジャッジ時間 5,485 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 8 ms
8,448 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 4 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 10 ms
9,728 KB
testcase_09 AC 10 ms
9,728 KB
testcase_10 AC 8 ms
9,088 KB
testcase_11 AC 8 ms
9,216 KB
testcase_12 AC 9 ms
9,344 KB
testcase_13 AC 21 ms
19,200 KB
testcase_14 AC 19 ms
18,304 KB
testcase_15 AC 20 ms
19,456 KB
testcase_16 AC 20 ms
18,688 KB
testcase_17 AC 20 ms
19,072 KB
testcase_18 AC 19 ms
18,560 KB
testcase_19 AC 20 ms
19,328 KB
testcase_20 AC 18 ms
17,920 KB
testcase_21 AC 20 ms
18,688 KB
testcase_22 AC 21 ms
19,328 KB
testcase_23 AC 21 ms
19,712 KB
testcase_24 AC 21 ms
19,584 KB
testcase_25 AC 22 ms
19,584 KB
testcase_26 AC 22 ms
19,584 KB
testcase_27 AC 22 ms
19,712 KB
testcase_28 AC 21 ms
19,712 KB
testcase_29 AC 22 ms
19,712 KB
testcase_30 AC 21 ms
19,584 KB
testcase_31 AC 21 ms
19,584 KB
testcase_32 AC 21 ms
19,712 KB
testcase_33 AC 21 ms
19,584 KB
testcase_34 AC 21 ms
19,712 KB
testcase_35 AC 21 ms
19,584 KB
testcase_36 AC 21 ms
19,840 KB
testcase_37 AC 21 ms
19,584 KB
testcase_38 AC 21 ms
19,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll=long long;
using Graph=vector<vector<int>>;
#define MAX 2000000
#define MOD 998244353
#define INF 1000000000

int main(){
  int N;
  cin>>N;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  vector<vector<ll>> dp(N+1,vector<ll>(20000+1,0));
  dp[0][10000]=1;
  for(int i=0;i<N;i++){
    for(int j=0;j<=20000;j++){
      if(j-A[i]>=0){
        dp[i+1][j-A[i]]+=dp[i][j];
        dp[i+1][j-A[i]]%=MOD;
      }
      if(j+A[i]<=20000){
        dp[i+1][j+A[i]]+=dp[i][j];
        dp[i+1][j+A[i]]%=MOD;
      }
    }
  }

  ll ans=0;
  for(int i=0;i<=20000;i++){
    ans+=dp[N][i]*(ll)abs(i-10000);
    ans%=MOD;
  }
  cout<<ans<<'\n';
}
0