結果

問題 No.1697 Deque House
ユーザー chineristACchineristAC
提出日時 2021-08-16 21:31:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 87 ms / 3,500 ms
コード長 2,847 bytes
コンパイル時間 13,271 ms
コンパイル使用メモリ 334,408 KB
実行使用メモリ 31,980 KB
最終ジャッジ日時 2023-09-26 15:42:57
合計ジャッジ時間 14,536 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
11,644 KB
testcase_01 AC 7 ms
11,744 KB
testcase_02 AC 6 ms
11,532 KB
testcase_03 AC 7 ms
11,548 KB
testcase_04 AC 7 ms
11,564 KB
testcase_05 AC 7 ms
11,516 KB
testcase_06 AC 6 ms
11,532 KB
testcase_07 AC 7 ms
11,572 KB
testcase_08 AC 6 ms
11,576 KB
testcase_09 AC 86 ms
31,980 KB
testcase_10 AC 47 ms
22,368 KB
testcase_11 AC 49 ms
22,352 KB
testcase_12 AC 39 ms
20,716 KB
testcase_13 AC 22 ms
14,960 KB
testcase_14 AC 32 ms
17,572 KB
testcase_15 AC 55 ms
22,588 KB
testcase_16 AC 54 ms
21,528 KB
testcase_17 AC 31 ms
17,348 KB
testcase_18 AC 35 ms
18,100 KB
testcase_19 AC 34 ms
18,176 KB
testcase_20 AC 87 ms
31,852 KB
testcase_21 AC 87 ms
31,808 KB
testcase_22 AC 87 ms
31,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <random>
#include <stdio.h>
#include <fstream>
#include <functional>
#include <cassert>
#include <atcoder/all>
#include "testlib.h"

using namespace std;
using namespace atcoder;

#define rep(i,n,c) for (int i=0;i<n;i+=c)
#define append push_back
#define all(x) (x).begin(), (x).end()

template<class T>
using vec = vector<T>;
template<class T>
using vvec = vec<vec<T>>;
template<class T>
using vvvec = vec<vvec<T>>;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;


template<class T>
bool chmin(T &a, T b){
  if (a>b){
    a = b;
    return true;
  }
  return false;
}

template<class T>
bool chmax(T &a, T b){
  if (a<b){
    a = b;
    return true;
  }
  return false;
}

template<class T>
T sum(vec<T> x){
  T res=0;
  for (auto e:x){
    res += e;
  }
  return res;
}

template<class T>
void printv(vec<T> x){
  for (auto e:x){
    cout<<e<<" ";
  }
  cout<<"\n";
}

int pow(int n,int k){
  int res = 1;
  while (k){
    if (k&1){
      res *= n;
    }
    n *= n;
    k >>= 1;
  }
  return res;
}

using mint = modint998244353;

mint f[15][100001];

int main(int argc,char* argv[]){
  registerValidation(argc,argv);

  int N = inf.readInt(2,100000);
  inf.readSpace();
  int K = inf.readInt(1,14);
  inf.readEoln();

  vec<mint> A(N);
  int a;
  for (int i=0;i<N;i++){
    a = inf.readInt(1,998244353-1);
    A[i] = (mint) a;
    if (i==N-1){
      inf.readEoln();
    }
    else{
      inf.readSpace();
    }
  }
  inf.readEof();

  mint ans = 0;

  for (int j=0;j<N;j++){
    f[0][j] = (mint)1;
  }
  mint t = 1;
  for (int i=1;i<=K;i++){
    t *= (mint) 2;
    f[i][0] = (mint) 1;
    for (int j=1;j<=N;j++){
      f[i][j] = t * f[i][j-1] + f[i-1][j];
    }
  }

  auto calc_dp = [&](){
    vec<vec<mint>> dp(N,vec<mint>(K+1,0));
    mint t = 1;
    for (int j=0;j<=K;j++){
      dp[0][j] = t;
      t = 2 * t * A[0];
    }
    for (int i=1;i<N;i++){
      dp[i][0] = dp[i-1][0];
      for (int j=0;j<=K;j++){
        dp[i][j] = dp[i-1][j] + dp[i][j-1];
      }
      mint t0 = 1;
      mint t1 = 1;
      for (int j=0;j<=K;j++){
        dp[i][j] = t0 * (f[j][i]*t1+dp[i][j]);
        t0 *= (mint) 2;
        t1 *= A[i];
      }
    }
    return dp;
  };

  auto dp = calc_dp();

  mint c = 2;
  c = c.pow(K);
  for (int i=1;i<N;i++){
    ans += (A[i].pow(K) * c * f[K][i-1] + dp[i-1][K]) * c * f[K-1][N-i-1];
  }

  reverse(all(A));
  auto rdp = calc_dp();

  for (int i=1;i<N-1;i++){
    for (int j=0;j<K;j++){
      ans += rdp[i-1][j] * c * c * f[K][N-2-i];
    }
  }

  mint i4 = 4;
  i4 = i4.inv();
  ans *= i4.pow(K);
  cout<<ans.val()<<endl; 
}
0