結果

問題 No.1645 AB's abs
ユーザー hamihami
提出日時 2021-11-27 09:39:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 927 bytes
コンパイル時間 2,005 ms
コンパイル使用メモリ 171,436 KB
実行使用メモリ 35,388 KB
最終ジャッジ日時 2023-09-12 13:05:11
合計ジャッジ時間 4,846 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,496 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 11 ms
13,148 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 3 ms
4,416 KB
testcase_05 AC 3 ms
4,840 KB
testcase_06 AC 4 ms
6,348 KB
testcase_07 AC 3 ms
4,700 KB
testcase_08 AC 14 ms
15,972 KB
testcase_09 AC 13 ms
16,264 KB
testcase_10 AC 12 ms
14,596 KB
testcase_11 AC 12 ms
14,724 KB
testcase_12 AC 13 ms
14,864 KB
testcase_13 AC 30 ms
34,660 KB
testcase_14 AC 29 ms
32,592 KB
testcase_15 AC 31 ms
34,660 KB
testcase_16 AC 30 ms
33,456 KB
testcase_17 AC 30 ms
34,136 KB
testcase_18 AC 29 ms
33,192 KB
testcase_19 AC 31 ms
34,848 KB
testcase_20 AC 28 ms
32,064 KB
testcase_21 AC 29 ms
33,344 KB
testcase_22 AC 30 ms
34,248 KB
testcase_23 AC 31 ms
35,372 KB
testcase_24 AC 31 ms
35,200 KB
testcase_25 AC 31 ms
35,240 KB
testcase_26 AC 31 ms
35,300 KB
testcase_27 AC 31 ms
35,192 KB
testcase_28 AC 31 ms
35,244 KB
testcase_29 AC 32 ms
35,240 KB
testcase_30 AC 32 ms
35,240 KB
testcase_31 AC 31 ms
35,316 KB
testcase_32 AC 31 ms
35,388 KB
testcase_33 AC 32 ms
35,240 KB
testcase_34 AC 32 ms
35,248 KB
testcase_35 AC 31 ms
35,236 KB
testcase_36 AC 32 ms
35,384 KB
testcase_37 AC 32 ms
35,232 KB
testcase_38 AC 32 ms
35,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<iostream>
using namespace std;
using LL = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
const int INF = 1 << 29;
const long long LINF = 1LL << 60;
#define all(x) (x).begin(), (x).end()
#define rep(i,n) for(int i = 0; i < (n); ++i)
template<class T>void chmin(T&a, T b){if(a > b) a = b;}
template<class T>void chmax(T&a, T b){if(a < b) a = b;}

const long long M = 998244353;

int main(){
	int N; cin >> N;
	vector<int> A(N); 
	for(int i = 0; i < N; ++i) cin >> A[i];

	vector<vector<long long>> dp(N+1, vector<long long>(40000, 0));
	dp[0][20000] = 1;

	for(int i = 0; i < N; ++i){
		for(int j = 0; j < 40000; ++j){
			if(dp[i][j]>0){
				dp[i+1][j+A[i]] += dp[i][j]%M;
				dp[i+1][j-A[i]] += dp[i][j]%M;
			}
		}
	}

	long long ans = 0;
	for(int i = 0; i < 40000; ++i){
		if(dp[N][i]){
			ans += dp[N][i]*abs(i - 20000)%M;
			ans %= M;
		}
	}
	cout << ans << endl;
}

0