結果
| 問題 |
No.1645 AB's abs
|
| コンテスト | |
| ユーザー |
Nachia
|
| 提出日時 | 2021-08-13 21:49:14 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 715 bytes |
| コンパイル時間 | 2,690 ms |
| コンパイル使用メモリ | 113,976 KB |
| 最終ジャッジ日時 | 2025-01-23 18:45:37 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 36 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <atcoder/modint>
using namespace std;
using i64 = int64_t;
using u64 = uint64_t;
#define rep(i,n) for(int i=0; i<(n); i++)
const i64 MOD = 998244353;
using m32 = atcoder::static_modint<MOD>;
int main() {
int N; cin >> N;
vector<int> A(N); rep(i,N) cin >> A[i];
int S = 0; for(int a : A) S += a;
vector<m32> dp(S+1,0);
dp[0] = 1;
for(int a : A){
for(int k=S; k>=a; k--) dp[k] += dp[k-a];
}
m32 ans = 0;
rep(i,S+1) ans += dp[i] * abs(i-(S-i));
cout << ans.val() << endl;
return 0;
}
struct ios_do_not_sync{
ios_do_not_sync(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
} ios_do_not_sync_instance;
Nachia