結果

問題 No.1239 Multiplication -2
ユーザー carrot46carrot46
提出日時 2020-09-25 22:39:00
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 106 ms / 2,000 ms
コード長 2,885 bytes
コンパイル時間 1,761 ms
コンパイル使用メモリ 178,848 KB
実行使用メモリ 4,776 KB
最終ジャッジ日時 2023-09-10 15:54:38
合計ジャッジ時間 4,844 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 34 ms
4,380 KB
testcase_16 AC 57 ms
4,376 KB
testcase_17 AC 98 ms
4,648 KB
testcase_18 AC 98 ms
4,776 KB
testcase_19 AC 101 ms
4,596 KB
testcase_20 AC 104 ms
4,768 KB
testcase_21 AC 96 ms
4,644 KB
testcase_22 AC 94 ms
4,384 KB
testcase_23 AC 73 ms
4,376 KB
testcase_24 AC 71 ms
4,376 KB
testcase_25 AC 55 ms
4,380 KB
testcase_26 AC 64 ms
4,376 KB
testcase_27 AC 29 ms
4,376 KB
testcase_28 AC 90 ms
4,380 KB
testcase_29 AC 98 ms
4,392 KB
testcase_30 AC 42 ms
4,376 KB
testcase_31 AC 64 ms
4,376 KB
testcase_32 AC 106 ms
4,640 KB
testcase_33 AC 74 ms
4,380 KB
testcase_34 AC 69 ms
4,388 KB
testcase_35 AC 35 ms
4,380 KB
testcase_36 AC 31 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include <chrono>
//#pragma GCC optimize("Ofast")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second

using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

ll N,M,H,W,Q,K,A,B;
string S;
typedef pair<ll, ll> P;
const ll INF = (1LL<<58);

template <unsigned long long mod > class modint{
public:
    ll x;
    constexpr modint(){x = 0;}
    constexpr modint(ll _x) : x((_x < 0 ? ((_x += (LLONG_MAX / mod) * mod) < 0 ? _x + (LLONG_MAX / mod) * mod : _x) : _x)%mod){}
    constexpr void set_raw(ll _x){
        //_x in [0, mod)
        x = _x;
    }
    constexpr modint operator-(){
        return x == 0 ? 0 : mod - x;
    }
    constexpr modint& operator+=(const modint& a){
        if((x += a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr modint operator+(const modint& a) const{
        return modint(*this) += a;
    }
    constexpr modint& operator-=(const modint& a){
        if((x -= a.x) < 0) x += mod;
        return *this;
    }
    constexpr modint operator-(const modint& a) const{
        return modint(*this) -= a;
    }
    constexpr modint& operator*=(const modint& a){
        (x *= a.x)%=mod;
        return *this;
    }
    constexpr modint operator*(const modint& a) const{
        return modint(*this) *= a;
    }
    constexpr modint pow(unsigned long long pw) const{
        modint res(1), comp(*this);
        while(pw){
            if(pw&1) res *= comp;
            comp *= comp;
            pw >>= 1;
        }
        return res;
    }
    //以下、modが素数のときのみ
    constexpr modint inv() const{
        return modint(*this).pow(mod - 2);
    }
    constexpr modint& operator/=(const modint &a){
        (x *= a.inv().x)%=mod;
        return *this;
    }
    constexpr modint operator/(const modint &a) const{
        return modint(*this) /= a;
    }
};
#define mod1 998244353
using mint = modint<mod1>;

ostream& operator<<(ostream& os, const mint& a){
    os << a.x;
    return os;
}
using vm = vector<mint>;

int main() {
    cin>>N;
    vec a(N);
    rep(i, N) cin>>a[i];
    map<int, mint> lst, nxt;
    lst[1] = 1;
    mint res(0);
    rep(i, N){
        for(int j = -2; j <= 2; ++j){
            int nj = j * a[i];
            if(abs(nj) > 2) nj = 0;
            nxt[nj] += lst[j];
            if(i != 0) {
                if (j == -2) res += lst[j] * mint(2).pow(max(0LL, N - 1 - i));
                nxt[a[i]] += lst[j];
            }
        }
        /*
        cout<<res<<endl;
        reps(j, -2, 3) cout<<nxt[j]<<' ';
        cout<<endl;
         */
        swap(lst, nxt);
        nxt.clear();
    }
    res += lst[-2];
    cout<<res * mint(2).pow(mod1 - N)<<endl;
}
0