結果
問題 | No.1645 AB's abs |
ユーザー | maimaicorgi |
提出日時 | 2022-09-27 13:43:07 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 103 ms / 2,000 ms |
コード長 | 2,674 bytes |
コンパイル時間 | 1,407 ms |
コンパイル使用メモリ | 145,760 KB |
実行使用メモリ | 21,252 KB |
最終ジャッジ日時 | 2023-08-24 03:50:25 |
合計ジャッジ時間 | 5,571 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
4,380 KB |
testcase_01 | AC | 4 ms
4,380 KB |
testcase_02 | AC | 17 ms
4,720 KB |
testcase_03 | AC | 4 ms
4,376 KB |
testcase_04 | AC | 4 ms
4,380 KB |
testcase_05 | AC | 5 ms
4,380 KB |
testcase_06 | AC | 6 ms
4,380 KB |
testcase_07 | AC | 4 ms
4,376 KB |
testcase_08 | AC | 21 ms
5,260 KB |
testcase_09 | AC | 23 ms
5,560 KB |
testcase_10 | AC | 18 ms
5,024 KB |
testcase_11 | AC | 20 ms
5,328 KB |
testcase_12 | AC | 20 ms
5,168 KB |
testcase_13 | AC | 73 ms
14,312 KB |
testcase_14 | AC | 58 ms
11,208 KB |
testcase_15 | AC | 76 ms
14,636 KB |
testcase_16 | AC | 72 ms
14,088 KB |
testcase_17 | AC | 73 ms
14,240 KB |
testcase_18 | AC | 63 ms
12,692 KB |
testcase_19 | AC | 71 ms
13,900 KB |
testcase_20 | AC | 61 ms
11,656 KB |
testcase_21 | AC | 66 ms
12,900 KB |
testcase_22 | AC | 74 ms
14,088 KB |
testcase_23 | AC | 71 ms
13,488 KB |
testcase_24 | AC | 73 ms
14,324 KB |
testcase_25 | AC | 78 ms
14,916 KB |
testcase_26 | AC | 70 ms
13,804 KB |
testcase_27 | AC | 77 ms
14,596 KB |
testcase_28 | AC | 72 ms
14,112 KB |
testcase_29 | AC | 72 ms
14,264 KB |
testcase_30 | AC | 77 ms
15,452 KB |
testcase_31 | AC | 76 ms
14,800 KB |
testcase_32 | AC | 79 ms
15,296 KB |
testcase_33 | AC | 100 ms
20,988 KB |
testcase_34 | AC | 102 ms
21,088 KB |
testcase_35 | AC | 101 ms
21,252 KB |
testcase_36 | AC | 101 ms
20,996 KB |
testcase_37 | AC | 103 ms
21,236 KB |
testcase_38 | AC | 37 ms
4,376 KB |
ソースコード
#include <iostream> #include <iomanip> #include <string> #include <vector> #include <cmath> #include <cstdlib> #include <algorithm> #include <ios> #include <iomanip> #include <queue> #include <numeric> #include <map> #include <set> #include <sstream> #include <bitset> #include <climits> #include <stack> #include <regex> #include <functional> #include <random> #ifdef _WIN64 # include <atcoder/all> #endif #ifdef _MSC_VER # include <intrin.h> # define __builtin_popcount __popcnt # define __builtin_popcountl __popcnt64 #endif using namespace std; #define ll long long #define rep(i, init, n) for(ll i = init; i < (ll)n; i++) #define rrep(i, init, n) for(ll i = init; i >= (ll)n; i--) #define all(x) (x).begin(), (x).end() #define sz(x) (ll)(x.size()) #define Out(x) cout << x << endl #define Yes cout << "Yes" << endl #define No cout << "No" << endl #define Ans cout << ans << endl #define PI 3.14159265358979 #define MOD 998244353 const int inf32 = INT_MAX / 2; const ll inf64 = 1LL << 60; template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template<class T>bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } // ------------------------------------------------------------------------------------------------- struct mint { ll x; mint(ll val = 0) { x = (val % MOD + MOD) % MOD; } mint operator-() const { return mint(-x); } mint& operator+=(const mint& other) { x += other.x; if (x >= MOD) x -= MOD; return *this; } mint& operator-=(const mint& other) { x -= other.x; if (x < 0) x += MOD; return *this; } mint& operator*=(const mint& other) { (x *= other.x) %= MOD; return *this; } mint& operator/=(const mint& other) { *this *= other.pow(MOD - 2); return *this; } mint operator+(const mint& other) const { return mint(*this) += other; } mint operator-(const mint& other) const { return mint(*this) -= other; } mint operator*(const mint& other) const { return mint(*this) *= other; } mint operator/(const mint& other) const { return mint(*this) /= other; } mint pow(ll i) const { mint ret = 1; for (mint tmp = x; i; tmp *= tmp, i >>= 1) if (i & 1) ret *= tmp; return ret; } friend ostream& operator<<(ostream& os, const mint& m) { os << m.x; return os; } }; int main() { int n; cin >> n; vector<int> a(n + 1); rep(i, 1, n + 1) cin >> a[i]; vector dp(n + 1, unordered_map<int, mint>()); dp[0][0] = 1; rep(i, 1, n + 1)rep(j, -10000, 10000 + 1) { if (dp[i - 1].count(j)) { dp[i][j + a[i]] += dp[i - 1][j]; dp[i][j - a[i]] += dp[i - 1][j]; } } mint ans = 0; rep(i, -10000, 10000 + 1) ans += (mint)abs(i) * dp[n][i]; Ans; return 0; }