結果

問題 No.1697 Deque House
ユーザー chineristAC
提出日時 2021-08-16 21:31:45
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,847 bytes
コンパイル時間 3,303 ms
コンパイル使用メモリ 213,464 KB
最終ジャッジ日時 2025-01-23 22:36:12
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
In file included from /usr/include/c++/13/string:43,
                 from /usr/include/c++/13/bits/locale_classes.h:40,
                 from /usr/include/c++/13/bits/ios_base.h:41,
                 from /usr/include/c++/13/ios:44,
                 from /usr/include/c++/13/ostream:40,
                 from /usr/include/c++/13/iostream:41,
                 from main.cpp:5:
/usr/include/c++/13/bits/allocator.h: In destructor ‘std::_Vector_base<char, std::allocator<char> >::_Vector_impl::~_Vector_impl()’:
/usr/include/c++/13/bits/allocator.h:184:7: error: inlining failed in call to ‘always_inline’ ‘std::allocator< <template-parameter-1-1> >::~allocator() noexcept [with _Tp = char]’: target specific option mismatch
  184 |       ~allocator() _GLIBCXX_NOTHROW { }
      |       ^
In file included from /usr/include/c++/13/vector:66,
                 from main.cpp:6:
/usr/include/c++/13/bits/stl_vector.h:133:14: note: called from here
  133 |       struct _Vector_impl
      |              ^~~~~~~~~~~~

ソースコード

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