結果

問題 No.2550 MORE! JUMP! MORE!
ユーザー dyktr_06dyktr_06
提出日時 2023-11-22 08:10:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 3,284 bytes
コンパイル時間 2,481 ms
コンパイル使用メモリ 204,592 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-11-22 08:10:13
合計ジャッジ時間 6,089 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

template <long long Modulus>
struct ModInt{
    long long val;
    constexpr ModInt(const long long &_val = 0) noexcept : val(_val) {
        normalize();
    }
    void normalize(){
        val = (val % Modulus + Modulus) % Modulus;
    }
    inline ModInt& operator+=(const ModInt& rhs) noexcept {
        if(val += rhs.val, val >= Modulus) val -= Modulus;
        return *this;
    }
    inline ModInt& operator-=(const ModInt& rhs) noexcept {
        if(val -= rhs.val, val < 0) val += Modulus;
        return *this;
    }
    inline ModInt& operator*=(const ModInt& rhs) noexcept {
        val = val * rhs.val % Modulus;
        return *this;
    }
    inline ModInt& operator/=(const ModInt& rhs) noexcept {
        val = val * inv(rhs.val).val % Modulus;
        return *this;
    }
    inline ModInt& operator++() noexcept {
        if(++val >= Modulus) val -= Modulus;
        return *this;
    }
    inline ModInt operator++(int) noexcept {
        ModInt t = val;
        if(++val >= Modulus) val -= Modulus;
        return t;
    }
    inline ModInt& operator--() noexcept {
        if(--val < 0) val += Modulus;
        return *this;
    }
    inline ModInt operator--(int) noexcept {
        ModInt t = val;
        if(--val < 0) val += Modulus;
        return t;
    }
    inline ModInt operator-() const noexcept { return (Modulus - val) % Modulus; }
    inline ModInt inv(void) const { return inv(val); }
    ModInt inv(const long long& n) const {
        long long a = n, b = Modulus, u = 1, v = 0;
        while(b){
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        u %= Modulus;
        if(u < 0) u += Modulus;
        return u;
    }
    friend inline ModInt operator+(const ModInt& lhs, const ModInt& rhs) noexcept { return ModInt(lhs) += rhs; }
    friend inline ModInt operator-(const ModInt& lhs, const ModInt& rhs) noexcept { return ModInt(lhs) -= rhs; }
    friend inline ModInt operator*(const ModInt& lhs, const ModInt& rhs) noexcept { return ModInt(lhs) *= rhs; }
    friend inline ModInt operator/(const ModInt& lhs, const ModInt& rhs) noexcept { return ModInt(lhs) /= rhs; }
    friend inline bool operator==(const ModInt& lhs, const ModInt& rhs) noexcept { return lhs.val == rhs.val; }
    friend inline bool operator!=(const ModInt& lhs, const ModInt& rhs) noexcept { return lhs.val != rhs.val; }
    friend inline istream& operator>>(istream& is, ModInt& x) noexcept {
        is >> x.val;
        x.normalize();
        return is;
    }
    friend inline ostream& operator<<(ostream& os, const ModInt& x) noexcept { return os << x.val; }
};

const long long MOD = 998244353;

using mint = ModInt<MOD>;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n; cin >> n;
    vector<mint> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }

    vector<mint> pow2(n + 1, 1);
    for(int i = 1; i <= n; i++){
        pow2[i] = pow2[i - 1] * 2;
    }

    mint ans = 0;
    for(long long i = 1; i <= n; i++){
        mint res = pow2[max(0LL, i - 2)] * (i - 1) + pow2[i - 1];
        res *= a[i - 1];
        res *= pow2[max(0LL, n - i - 1LL)];
        ans += res;
    }
    cout << ans << endl;
}
0