結果

問題 No.985 Hadamard
ユーザー beetbeet
提出日時 2020-01-27 14:41:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 2,422 bytes
コンパイル時間 1,957 ms
コンパイル使用メモリ 201,616 KB
実行使用メモリ 9,132 KB
最終ジャッジ日時 2023-07-24 10:35:05
合計ジャッジ時間 4,875 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 78 ms
9,016 KB
testcase_05 AC 39 ms
6,152 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 37 ms
6,168 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 73 ms
9,128 KB
testcase_14 AC 72 ms
9,012 KB
testcase_15 AC 71 ms
9,132 KB
testcase_16 AC 72 ms
9,048 KB
testcase_17 AC 71 ms
9,008 KB
testcase_18 AC 72 ms
9,120 KB
testcase_19 AC 74 ms
9,124 KB
testcase_20 AC 74 ms
9,048 KB
testcase_21 AC 76 ms
9,048 KB
testcase_22 AC 75 ms
9,124 KB
testcase_23 AC 62 ms
9,096 KB
testcase_24 AC 62 ms
9,064 KB
testcase_25 AC 64 ms
9,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}


template<typename T,T MOD = 1000000007>
struct Mint{
  static constexpr T mod = MOD;
  T v;
  Mint():v(0){}
  Mint(signed v):v(v){}
  Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}

  Mint pow(long long k){
    Mint res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }

  static Mint add_identity(){return Mint(0);}
  static Mint mul_identity(){return Mint(1);}

  Mint inv(){return pow(MOD-2);}

  Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
  Mint& operator/=(Mint a){return (*this)*=a.inv();}

  Mint operator+(Mint a) const{return Mint(v)+=a;}
  Mint operator-(Mint a) const{return Mint(v)-=a;}
  Mint operator*(Mint a) const{return Mint(v)*=a;}
  Mint operator/(Mint a) const{return Mint(v)/=a;}

  Mint operator-() const{return v?Mint(MOD-v):Mint(v);}

  bool operator==(const Mint a)const{return v==a.v;}
  bool operator!=(const Mint a)const{return v!=a.v;}
  bool operator <(const Mint a)const{return v <a.v;}

  static Mint comb(long long n,int k){
    Mint num(1),dom(1);
    for(int i=0;i<k;i++){
      num*=Mint(n-i);
      dom*=Mint(i+1);
    }
    return num/dom;
  }
};
template<typename T,T MOD> constexpr T Mint<T, MOD>::mod;
template<typename T,T MOD>
ostream& operator<<(ostream &os,Mint<T, MOD> m){os<<m.v;return os;}


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;

//INSERT ABOVE HERE

signed main(){
  int n;
  cin>>n;
  int sz=1<<n;

  using ll = long long;
  vector<ll> cs(sz),ls(sz),hs(sz);
  for(int i=0;i<sz;i++) cin>>cs[i];
  for(int i=0;i<sz;i++) cin>>ls[i]>>hs[i];

  for(int d=1;d<sz;d<<=1){
    for(int m=d<<1,i=0;i<sz;i+=m){
      for(int j=0;j<d;j++){
        auto x=cs[i+j+0],y=cs[i+j+d];
        cs[i+j+0]=x+y;
        cs[i+j+d]=x-y;
      }
    }
  }

  using M = Mint<int, 998244353>;
  M ans{0};
  for(int i=0;i<sz;i++){
    if(cs[i]<0) ans+=M(cs[i])*M(ls[i]);
    else ans+=M(cs[i])*M(hs[i]);
  }
  ans/=M(sz);
  cout<<ans<<endl;
  return 0;
}
0