結果

問題 No.2717 Sum of Subarray of Subsequence
ユーザー GOTKAKOGOTKAKO
提出日時 2024-04-05 22:01:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 2,446 bytes
コンパイル時間 2,170 ms
コンパイル使用メモリ 205,616 KB
実行使用メモリ 12,800 KB
最終ジャッジ日時 2024-04-05 22:01:44
合計ジャッジ時間 3,709 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 3 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 1 ms
6,676 KB
testcase_09 AC 55 ms
12,672 KB
testcase_10 AC 58 ms
12,672 KB
testcase_11 AC 58 ms
12,672 KB
testcase_12 AC 56 ms
12,672 KB
testcase_13 AC 56 ms
12,800 KB
testcase_14 AC 56 ms
12,672 KB
testcase_15 AC 57 ms
12,672 KB
testcase_16 AC 54 ms
12,672 KB
testcase_17 AC 55 ms
12,672 KB
testcase_18 AC 56 ms
12,800 KB
testcase_19 AC 55 ms
12,672 KB
testcase_20 AC 1 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 54 ms
12,800 KB
testcase_23 AC 44 ms
12,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

long long mod = 998244353;
//入力が必ずmod未満の時に使う.
struct mint{
    long long v = 0;
    mint(){} mint(int a){v = a;} mint(long long a){v = a;} mint(unsigned long long a){v = a;}
    long long val(){return v;}
    void modu(){v %= mod;}
 
    mint repeat2mint(long long a,long long b){
        mint ret = 1,p = a;
        while(b){if(b&1) ret *= p; p *= p; b >>= 1;}
        return ret;
    };
 
    mint operator-(){return mint(0)-mint(v);}
    mint operator+(mint b){return (v+b.v)%mod;}
    mint operator-(mint b){return (v-b.v+mod)%mod;}
    mint operator*(mint b){return v*b.v%mod;}
    mint operator/(mint b){
        if(b.v == 0) assert(false);
        return v*(repeat2mint(b.v,mod-2)).v%mod;
    }
 
    void operator+=(mint b){v = (v+b.v)%mod;}
    void operator-=(mint b){v = (v-b.v+mod)%mod;}
    void operator*=(mint b){v = v*b.v%mod;}
    void operator/=(mint b){
    if(b.v == 0) assert(false);
        v = v*repeat2mint(b.v,mod-2).v%mod;
    }
 
    void operator++(int){v = (v+1)%mod; return;}
    void operator--(int){v = (v-1+mod)%mod; return;}
    bool operator==(mint b){return v == b.v;}
    bool operator!=(mint b){return v != b.v;}
    bool operator>(mint b) {return v >  b.v;}
    bool operator>=(mint b){return v >= b.v;}
    bool operator<(mint b) {return v <  b.v;}
    bool operator<=(mint b){return v <= b.v;}
 
    mint pow(long long x){return repeat2mint(v,x);}
    mint inv(){return mint(1)/v;}
};			

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int N; cin >> N;
    vector<mint> A(N);
    for(auto &a : A) cin >> a.v;

    int Limit = N;
    vector<mint> fac(Limit+1,1),inv(Limit+1,1),facinv(Limit+1,1);
    for(int i=1; i<=Limit; i++) fac.at(i).v = fac.at(i-1).v*i %mod;
    for(int i=2; i<=Limit; i++) inv.at(i).v = mod-(mod/i*inv.at(mod%i).v %mod);
    for(int i=2; i<=Limit; i++) facinv.at(i).v = facinv.at(i-1).v*inv.at(i).v %mod;
    auto nCr = [&](int n, int r) -> mint {
        //if(n < r) return mint(0);
        return fac.at(n)*facinv.at(r)*facinv.at(n-r);
    };


    vector<mint> p2(N,1);
    for(int i=1; i<N; i++) p2.at(i) = p2.at(i-1)*2;
    vector<mint> NCr(N,1);
    for(int i=1; i<N; i++) NCr.at(i) = p2.at(i)+p2.at(i-1)*i;

    mint answer = 0;
    for(int i=0; i<N; i++){
        int l = i,r = N-1-i;
        answer += NCr.at(l)*NCr.at(r)*A.at(i);
    }
    cout << answer.v << endl;
}
0