結果

問題 No.1325 Subsequence Score
ユーザー DaYuanChiDaYuanChi
提出日時 2021-01-20 21:11:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 566 ms / 2,000 ms
コード長 1,988 bytes
コンパイル時間 1,650 ms
コンパイル使用メモリ 170,048 KB
実行使用メモリ 5,008 KB
最終ジャッジ日時 2023-08-25 01:11:29
合計ジャッジ時間 11,277 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
4,376 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 551 ms
4,884 KB
testcase_14 AC 150 ms
4,384 KB
testcase_15 AC 456 ms
4,668 KB
testcase_16 AC 525 ms
4,876 KB
testcase_17 AC 229 ms
4,380 KB
testcase_18 AC 130 ms
4,380 KB
testcase_19 AC 562 ms
5,008 KB
testcase_20 AC 71 ms
4,500 KB
testcase_21 AC 187 ms
4,384 KB
testcase_22 AC 233 ms
4,376 KB
testcase_23 AC 566 ms
4,932 KB
testcase_24 AC 565 ms
4,944 KB
testcase_25 AC 564 ms
5,000 KB
testcase_26 AC 559 ms
4,824 KB
testcase_27 AC 563 ms
4,904 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

//combination mod prime
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main(){
  int n; cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  //s(k)=2^(n-k)∑_(i=1~k)k-1Ci-1*i={2^(k-1)+(k-1)*2^(k-2)}*2^(n-k)
  //ans = ∑_(k=1~n)s[k]*a[k]
  mint ans = 0;
  ans += mint(a[0])*mint(2).pow(n-1);
  for(int i = 2; i <= n; i++){
    mint s = mint(2).pow(i-1)+mint(i-1)*mint(2).pow(i-2);
    s *= mint(a[i-1])*mint(2).pow(n-i);
    ans += s;
  }
  cout << ans << endl;
  return 0;
}
0