結果

問題 No.1239 Multiplication -2
ユーザー gyouzasushigyouzasushi
提出日時 2020-09-25 22:42:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,789 bytes
コンパイル時間 2,102 ms
コンパイル使用メモリ 201,564 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-09-10 15:56:23
合計ジャッジ時間 4,573 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 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 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 65 ms
4,380 KB
testcase_22 AC 50 ms
4,376 KB
testcase_23 WA -
testcase_24 AC 41 ms
4,380 KB
testcase_25 AC 17 ms
4,384 KB
testcase_26 AC 45 ms
4,380 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 998244353;
const ll LINF = 1e18;
template <class T>
void get_unique(vector<T>& x) {
    x.erase(unique(x.begin(), x.end()), x.end());
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (int i = 0; i < sz(v); i++) {
        os << v[i];
        if (i < sz(v) - 1) os << " ";
    }
    return os;
}
ll ext_gxd(ll a, ll b, ll& x, ll& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll q = a / b;
    ll g = ext_gxd(b, a - q * b, x, y);
    ll z = x - q * y;
    x = y;
    y = z;
    return g;
}

ll modinv(ll a, ll m = MOD) {
    ll x, y;
    ext_gxd(a, m, x, y);
    x %= m;
    if (x < 0) x += m;
    return x;
}

ll modpow(ll a, ll n, ll m = MOD) {
    ll ret = 1;
    ll now = a;
    while (n > 0) {
        if (n % 2 == 1) ret = ret * now % m;
        now = now * now % m;
        n /= 2;
    }
    return ret;
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    ll ans = 0;
    rep(i, n) {
        if (abs(a[i]) != 2) continue;
        int l = i;
        while (l - 1 >= 0 && abs(a[l - 1]) == 1) l--;
        int r = i;
        while (r + 1 < n && abs(a[r + 1]) == 1) r++;

        ll l1 = 0, l2 = 0, r1 = 0, r2 = 0;
        ll now = 1;
        for (int j = i; j >= l; j--) {
            if (now == 1) {
                l1 += modpow(2, j - 1);
            } else {
                l2 += modpow(2, j - 1);
            }
            if (j - 1 >= 0) now *= a[j - 1];
        }
        now = 1;
        for (int j = i; j <= r; j++) {
            if (now == 1) {
                r1 += modpow(2, n - 2 - j);
            } else {
                r2 += modpow(2, n - 2 - j);
            }
            if (j + 1 < n) now *= a[j + 1];
        }
        if (a[i] == 2) {
            (ans += l1 * r2 % MOD) %= MOD;
            (ans += l2 * r1 % MOD) %= MOD;
        } else {
            (ans += l1 * r1 % MOD) %= MOD;
            (ans += l2 * r2 % MOD) %= MOD;
        }
    }
    (ans *= modinv(modpow(2, n - 1))) %= MOD;
    cout << ans << '\n';
}
0