//generated by GPT-5.4?, modified by hamamu namespace ArrayMatSpace{ using ll=long long; template struct PlusTimesOps{ static T zero(){ return T(0); } static T one() { return T(1); } static T add(const T &a,const T &b){ return a+b; } static T mul(const T &a,const T &b){ return a*b; } }; template> struct arraymat_{ using value_type=T; using row_type=std::array; using storage_type=std::array; storage_type a; arraymat_(){ for (ll i=0; i> init): arraymat_(){ ll i=0; for (auto &&row: init){ assert(i operator*(const std::vector &v) const { assert((ll)v.size()==N); std::vector ret(N,Ops::zero()); for (ll i=0; i0; n>>=1,base*=base) if (n&1) ret*=base; return ret; } arraymat_ t() const { arraymat_ ret; for (ll i=0; i; using mat3 = arraymat_; /* array版行列クラス サイズ固定、正方行列のみ対応 mat2 m={{2,3},{1,0}}; mat2 m; //2x2,all0 mat3 m; //3x3,all0 mat2 m("E"); //単位行列 A+B A*B A+=B A*=B //Opsのadd,mulでの行列演算 vmll u=A*v //Opsのmulでの行列とベクトルの積 A-B A-=B -A //Opsを無視して加減算 A*k A*=k //Opsを無視して各要素をk倍 mat2 mm=m.pow(k); //m^k mat2 mm=m.t(); //転置 - ---- min-plus半環 (最短路計算など) struct MinPlusOpsLL{ static ll zero(){ return INF; } static ll one() { return 0; } static ll add(ll a,ll b){ return min(a,b); } static ll mul(ll a,ll b){ if(a>=INF || b>=INF) return INF; return min(INF,a+b); } }; using minmat2 = arraymat_; その他半環はメモ参照 */