結果

問題 No.1645 AB's abs
コンテスト
ユーザー Drice27149
提出日時 2021-08-13 21:40:38
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 673 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 333 ms
コンパイル使用メモリ 74,112 KB
実行使用メモリ 19,584 KB
最終ジャッジ日時 2026-04-19 19:22:17
合計ジャッジ時間 2,044 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <cstdio>
#include <iostream>
using std::string;
const long long mod = 998244353;
long long f[105][20005];
//int a[105];

int main(){
	int n;
	scanf("%d",&n);
	int off = 10001;
	f[0][off] = 1;
	long long ans = 0;
	for(int i = 1; i <= n; i++){
		int u;
		scanf("%d",&u);
		for(int j = -10000; j <= 10000; j++){
			f[i][j+off] = 0;
			int last = j-u;
			if(last>=-10000) f[i][j+off] += f[i-1][last+off];
			f[i][j+off] %= mod;
			last = j+u;
			if(last<=10000) f[i][j+off] += f[i-1][last+off];
			f[i][j+off] %= mod;
			if(i==n){
				long long val = j;
				if(j<0) val *= -1;
				ans = (ans + val*f[i][j+off]%mod)%mod;
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}
0