結果
問題 |
No.1645 AB's abs
|
ユーザー |
|
提出日時 | 2023-04-13 15:41:42 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 30 ms / 2,000 ms |
コード長 | 739 bytes |
コンパイル時間 | 823 ms |
コンパイル使用メモリ | 81,980 KB |
実行使用メモリ | 19,072 KB |
最終ジャッジ日時 | 2024-10-09 13:18:04 |
合計ジャッジ時間 | 3,056 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
ソースコード
#include<cstdio> #include<cstring> #include<iostream> #include<cmath> #include<ctime> #include<string> #include<algorithm> #include<vector> #include<queue> #include<stack> #include<map> using namespace std; typedef long long LL; const int Z=1e4; const int MOD=998244353; int n; int a[101]; LL dp[101][2*Z+1]; int main(){ cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; dp[0][Z]=1; for(int i=1;i<=n;i++){ for(int j=-Z;j<=Z;j++){ if(j-a[i]>=-Z) dp[i][Z+j]+=dp[i-1][Z+j-a[i]]; if(j+a[i]<=Z) dp[i][Z+j]+=dp[i-1][Z+j+a[i]]; dp[i][Z+j]%=MOD; } } LL ans=0; for(int j=-Z;j<=Z;j++){ ans+=abs(j)*dp[n][Z+j]; ans%=MOD; } cout<<ans<<endl; return 0; }