結果

問題 No.1239 Multiplication -2
ユーザー longrunlongrun
提出日時 2020-09-25 23:32:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 3,648 bytes
コンパイル時間 2,327 ms
コンパイル使用メモリ 204,544 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-10 17:08:09
合計ジャッジ時間 4,136 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,384 KB
testcase_15 AC 11 ms
4,380 KB
testcase_16 AC 18 ms
4,384 KB
testcase_17 AC 26 ms
4,380 KB
testcase_18 AC 26 ms
4,384 KB
testcase_19 AC 28 ms
4,384 KB
testcase_20 AC 29 ms
4,380 KB
testcase_21 AC 26 ms
4,384 KB
testcase_22 AC 26 ms
4,380 KB
testcase_23 AC 22 ms
4,384 KB
testcase_24 AC 22 ms
4,384 KB
testcase_25 AC 15 ms
4,384 KB
testcase_26 AC 18 ms
4,384 KB
testcase_27 AC 10 ms
4,380 KB
testcase_28 AC 28 ms
4,384 KB
testcase_29 AC 30 ms
4,384 KB
testcase_30 AC 13 ms
4,380 KB
testcase_31 AC 20 ms
4,384 KB
testcase_32 AC 32 ms
4,380 KB
testcase_33 AC 23 ms
4,384 KB
testcase_34 AC 22 ms
4,380 KB
testcase_35 AC 11 ms
4,384 KB
testcase_36 AC 10 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
#define rep2(i,m,n) for (int i = (m); i < (n); ++i)
#define rep(i,n) rep2(i,0,n)
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> P;
template<typename T> struct V : vector<T> { using vector<T>::vector; };
V() -> V<int>;
V(size_t) -> V<int>;
template<typename T> V(size_t, T) -> V<T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
const int INF = 1<<30;
const ll LINF = 1LL<<61;
const ll MOD = 998244353;

struct mint
{
    ll x;
    mint(ll x = 0) : x(x % MOD) {}
    mint& operator+=(const mint rh) { if((x += rh.x) >= MOD) x -= MOD; return *this; }
    mint& operator-=(const mint rh) { if((x += MOD-rh.x) >= MOD) x -= MOD; return *this; }
    mint& operator*=(const mint rh) { (x *= rh.x) %= MOD; return *this; }
    mint operator+(const mint rh) const { return mint(*this) += rh; }
    mint operator-(const mint rh) const { return mint(*this) -= rh; }
    mint operator*(const mint rh) const { return mint(*this) *= rh; }
    mint pow(ll k) const
    {
        if(!k) return 1;
        mint a = x;
        mint res = 1;
        while(k)
        {
            if(k & 1) res *= a;
            k >>= 1;
            a *= a;
        }
        return res;
    }
    mint inv() const { return pow(MOD-2); }
    mint& operator/=(const mint rh) { return *this *= rh.inv(); }
    mint operator/(const mint rh) { return mint(*this) /= rh; }
};

long long mpow(long long x, int k, long long MOD = MOD)
{
    long long res = 1;
    while(k)
    {
        if(k & 1) res = (res * x) % MOD;
        k >>= 1;
        x = (x * x) % MOD;
    }
    return res;
}

long long modinv(long long a, long long m = MOD)
{
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<mint> dp0(6), dp1(6);
    int ofs = 2;
    dp1[a[0] + ofs] = 1;
    for(int i=1; i<n; i++)
    {
        vector<mint> dp02(6), dp12(6);
        for(int j=-2; j<=3; j++)
        {
            //区切らない
            int nj = j * a[i];
            if(abs(nj) <= 2)
            {
                dp02[nj+ofs] += dp0[j+ofs];
                dp12[nj+ofs] += dp1[j+ofs];
            }
            else
            {
                dp02[5] += dp0[j+ofs];
                dp12[5] += dp1[j+ofs];
            }
            
            //区切る
            nj = a[i];
            if(j == -2)
            {
                dp02[nj+ofs] += dp0[j+ofs] + dp1[j+ofs];
            }
            else
            {
                dp02[nj+ofs] += dp0[j+ofs];
            }
            dp12[nj+ofs] += dp1[j+ofs];
        }
        swap(dp0, dp02);
        swap(dp1, dp12);
    }
    mint q = mpow(2, n-1);
    mint ans = dp1[0];
    rep(i,6) ans += dp0[i];
    ans /= q;
    cout << ans.x << endl;

    return 0;
}
0