結果
| 問題 | No.1645 AB's abs |
| コンテスト | |
| ユーザー |
siman
|
| 提出日時 | 2021-08-17 07:38:14 |
| 言語 | C++17(clang) (clang++ 22.1.2 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 10 ms / 2,000 ms |
| コード長 | 911 bytes |
| 記録 | |
| コンパイル時間 | 686 ms |
| コンパイル使用メモリ | 151,296 KB |
| 実行使用メモリ | 19,456 KB |
| 最終ジャッジ日時 | 2026-04-26 04:43:53 |
| 合計ジャッジ時間 | 2,149 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 36 |
コンパイルメッセージ
main.cpp:29:16: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
29 | ll dp[N + 1][2 * sum + 1];
| ^~~~~~~~~~~
main.cpp:29:20: note: read of non-const variable 'sum' is not allowed in a constant expression
29 | ll dp[N + 1][2 * sum + 1];
| ^
main.cpp:22:6: note: declared here
22 | ll sum = 0;
| ^
main.cpp:29:9: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
29 | ll dp[N + 1][2 * sum + 1];
| ^~~~~
main.cpp:29:9: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:19:7: note: declared here
19 | int N;
| ^
2 warnings generated.
ソースコード
#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
int main() {
int N;
cin >> N;
vector<ll> A(N);
ll sum = 0;
for (int i = 0; i < N; ++i) {
cin >> A[i];
sum += A[i];
}
ll dp[N + 1][2 * sum + 1];
memset(dp, 0, sizeof(dp));
dp[0][sum] = 1;
for (int i = 0; i < N; ++i) {
ll a = A[i];
for (int v = 0; v <= 2 * sum; ++v) {
if (dp[i][v] == 0) continue;
dp[i + 1][v - a] += dp[i][v];
dp[i + 1][v + a] += dp[i][v];
dp[i + 1][v - a] %= MOD;
dp[i + 1][v + a] %= MOD;
}
}
ll ans = 0;
for (int v = 0; v <= 2 * sum; ++v) {
ans += dp[N][v] * abs(v - sum);
ans %= MOD;
}
cout << ans << endl;
return 0;
}
siman