結果
| 問題 |
No.1645 AB's abs
|
| コンテスト | |
| ユーザー |
monnu
|
| 提出日時 | 2021-08-19 22:48:03 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 21 ms / 2,000 ms |
| コード長 | 751 bytes |
| コンパイル時間 | 3,820 ms |
| コンパイル使用メモリ | 231,084 KB |
| 実行使用メモリ | 19,712 KB |
| 最終ジャッジ日時 | 2024-10-13 00:43:07 |
| 合計ジャッジ時間 | 5,145 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 36 |
ソースコード
#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';
}
monnu