結果

問題 No.1645 AB's abs
ユーザー 蜜蜂蜜蜂
提出日時 2021-05-15 11:05:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 1,194 bytes
コンパイル時間 4,040 ms
コンパイル使用メモリ 225,936 KB
実行使用メモリ 8,492 KB
最終ジャッジ日時 2024-04-14 15:44:40
合計ジャッジ時間 5,701 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,336 KB
testcase_01 AC 4 ms
8,312 KB
testcase_02 AC 5 ms
8,224 KB
testcase_03 AC 4 ms
8,304 KB
testcase_04 AC 4 ms
8,236 KB
testcase_05 AC 4 ms
8,200 KB
testcase_06 AC 5 ms
8,372 KB
testcase_07 AC 4 ms
8,356 KB
testcase_08 AC 5 ms
8,236 KB
testcase_09 AC 5 ms
8,116 KB
testcase_10 AC 5 ms
8,324 KB
testcase_11 AC 4 ms
8,292 KB
testcase_12 AC 5 ms
8,168 KB
testcase_13 AC 5 ms
8,156 KB
testcase_14 AC 5 ms
8,352 KB
testcase_15 AC 6 ms
8,224 KB
testcase_16 AC 5 ms
8,264 KB
testcase_17 AC 5 ms
8,248 KB
testcase_18 AC 5 ms
8,212 KB
testcase_19 AC 5 ms
8,192 KB
testcase_20 AC 4 ms
8,116 KB
testcase_21 AC 4 ms
8,352 KB
testcase_22 AC 5 ms
8,492 KB
testcase_23 AC 6 ms
8,208 KB
testcase_24 AC 6 ms
8,348 KB
testcase_25 AC 5 ms
8,172 KB
testcase_26 AC 6 ms
8,032 KB
testcase_27 AC 6 ms
8,240 KB
testcase_28 AC 5 ms
8,484 KB
testcase_29 AC 6 ms
8,224 KB
testcase_30 AC 5 ms
8,276 KB
testcase_31 AC 4 ms
8,476 KB
testcase_32 AC 5 ms
8,184 KB
testcase_33 AC 5 ms
8,208 KB
testcase_34 AC 5 ms
8,240 KB
testcase_35 AC 6 ms
8,036 KB
testcase_36 AC 6 ms
8,208 KB
testcase_37 AC 6 ms
8,228 KB
testcase_38 AC 6 ms
8,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//g++ 1.cpp -std=c++14 -O2 -I .
#include <bits/stdc++.h>
using namespace std;

#include <atcoder/all>
using namespace atcoder;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vld = vector<ld>;
using vvld = vector<vld>;

#define fi first
#define se second
#define pb push_back
#define pq_big(T) priority_queue<T,vector<T>,less<T>>
#define pq_small(T) priority_queue<T,vector<T>,greater<T>>
#define all(a) a.begin(),a.end()
#define rep(i,start,end) for(ll i=start;i<(ll)(end);i++)
#define per(i,start,end) for(ll i=start;i>=(ll)(end);i--)

using mint = modint998244353;

mint dp[110][11000]={};
//dp[i][j] := A_iまでに総和jとなる通り数

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

  int n;
  cin>>n;

  vi a(n);
  int sum=0;
  rep(i,0,n){
    cin>>a[i];
    sum+=a[i];
  }

  dp[0][0]=1;
  rep(i,0,n){
    rep(j,0,10100){
      dp[i+1][j+a[i]]=dp[i][j];
      dp[i+1][j]+=dp[i][j];
    }
  }

  mint ans=0;
  rep(i,0,10100){
    int x=abs(sum-2*i);
    ans+=dp[n][i]*x;
  }

  cout<<ans.val()<<endl;
}
0