結果

問題 No.1325 Subsequence Score
ユーザー tsutajtsutaj
提出日時 2020-12-03 22:55:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 407 ms / 2,000 ms
コード長 2,493 bytes
コンパイル時間 713 ms
コンパイル使用メモリ 75,300 KB
実行使用メモリ 7,228 KB
最終ジャッジ日時 2023-10-17 16:35:56
合計ジャッジ時間 8,563 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 3 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 3 ms
4,348 KB
testcase_13 AC 400 ms
7,228 KB
testcase_14 AC 108 ms
4,392 KB
testcase_15 AC 335 ms
6,504 KB
testcase_16 AC 380 ms
6,964 KB
testcase_17 AC 162 ms
4,920 KB
testcase_18 AC 91 ms
4,392 KB
testcase_19 AC 407 ms
7,228 KB
testcase_20 AC 50 ms
4,348 KB
testcase_21 AC 134 ms
4,656 KB
testcase_22 AC 166 ms
4,920 KB
testcase_23 AC 405 ms
7,228 KB
testcase_24 AC 405 ms
7,228 KB
testcase_25 AC 404 ms
7,228 KB
testcase_26 AC 407 ms
7,228 KB
testcase_27 AC 405 ms
7,228 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

// ModInt begin

using ll = long long;
template<ll mod>
struct ModInt {
    ll v;
    ll mod_pow(ll x, ll n) const {
        return (!n) ? 1 : (mod_pow((x*x)%mod,n/2) * ((n&1)?x:1)) % mod;
    }
    ModInt(ll a = 0) : v((a %= mod) < 0 ? a + mod : a) {}
    ModInt operator+ ( const ModInt& b ) const {
        return (v + b.v >= mod ? ModInt(v + b.v - mod) : ModInt(v + b.v));
    }
    ModInt operator- () const {
        return ModInt(-v);
    }
    ModInt operator- ( const ModInt& b ) const {
        return (v - b.v < 0 ? ModInt(v - b.v + mod) : ModInt(v - b.v));
    }
    ModInt operator* ( const ModInt& b ) const {return (v * b.v) % mod;}
    ModInt operator/ ( const ModInt& b ) const {return (v * mod_pow(b.v, mod-2)) % mod;}
    
    bool operator== ( const ModInt &b ) const {return v == b.v;}
    bool operator!= ( const ModInt &b ) const {return !(*this == b); }
    ModInt& operator+= ( const ModInt &b ) {
        v += b.v;
        if(v >= mod) v -= mod;
        return *this;
    }
    ModInt& operator-= ( const ModInt &b ) {
        v -= b.v;
        if(v < 0) v += mod;
        return *this;
    }
    ModInt& operator*= ( const ModInt &b ) {
        (v *= b.v) %= mod;
        return *this;
    }
    ModInt& operator/= ( const ModInt &b ) {
        (v *= mod_pow(b.v, mod-2)) %= mod;
        return *this;
    }
    ModInt pow(ll x) { return ModInt(mod_pow(v, x)); }
    // operator int() const { return int(v); }
    // operator long long int() const { return v; }
};

template<ll mod>
ModInt<mod> pow(ModInt<mod> n, ll k) {
    return ModInt<mod>(n.mod_pow(n.v, k));
}

template<ll mod>
ostream& operator<< (ostream& out, ModInt<mod> a) {return out << a.v;}
template<ll mod>
istream& operator>> (istream& in, ModInt<mod>& a) {
    in >> a.v;
    return in;
}

// ModInt end

using ll = long long int;
using mint = ModInt<998244353LL>;

int main() {
    int N; scanf("%d", &N);
    vector<ll> A(N);
    for(int i=0; i<N; i++) scanf("%lld", &A[i]);
    reverse(A.begin(), A.end());

    mint ans(0);
    for(int i=0; i<N; i++) {
        // 自分より前はあってもなくても良い
        mint mul = mint(2).pow(i);
        ans += mint(2).pow(N-1) * mint(A[i]);
        // 自分より後について (その要素が含まれるのが 2^(N-i-1) 通り)
        ans += mul * mint(2).pow(N-i-2) * mint(N-i-1) * A[i];
    }
    cout << ans << endl;
    return 0;
}
0