結果
問題 |
No.3243 Multiplication 8 1
|
ユーザー |
|
提出日時 | 2025-08-22 22:31:21 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 88 ms / 2,000 ms |
コード長 | 2,865 bytes |
コンパイル時間 | 3,633 ms |
コンパイル使用メモリ | 300,576 KB |
実行使用メモリ | 7,712 KB |
最終ジャッジ日時 | 2025-08-22 22:31:26 |
合計ジャッジ時間 | 4,552 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 4 |
ソースコード
#include<bits/stdc++.h> #if __has_include(<atcoder/all>) #include<atcoder/modint> #endif using namespace std; #define LL(...) ll __VA_ARGS__;lin(__VA_ARGS__) #define FO(n) for(ll IJK=n;IJK-->0;) #define fo(i,...) for(auto[i,i##stop,i##step]=for_range<ll>(0,__VA_ARGS__);i<i##stop;i+=i##step) #define defpp template<ostream&o=cout>void pp(const auto&...a){[[maybe_unused]]const char*c="";((o<<c<<a,c=" "),...);o<<'\n';}void epp(const auto&...a){pp<cerr>(a...);} #define entry defpp void main();void main2();}int main(){my::io();my::main();}namespace my{ #define multiple_testcases LL(T);FO(T)main2();}void main2(){ #define use_ml998244353 using ml=atcoder::modint998244353; namespace my{ auto&operator<<(ostream&o,const atcoder::modint998244353&x){return o<<(int)x.val();} void io(){cin.tie(nullptr)->sync_with_stdio(0);cout<<fixed<<setprecision(15);} using ll=long long; template<class T>constexpr auto for_range(T s,T b){T a=0;if(s)swap(a,b);return array{a-s,b,1-s*2};} void lin(auto&...a){(cin>>...>>a);} constexpr auto pow(auto x,ll n,auto e){assert(n>=0);decltype(x)r=e;for(;n;x*=x,n>>=1)if(n&1)r*=x;return r;} template<class...A>using pack_back_t=tuple_element_t<sizeof...(A)-1,tuple<A...>>; } namespace my{ template<class V>struct vec; template<int D,class T>struct hvec_helper{using type=vec<typename hvec_helper<D-1,T>::type>;}; template<class T>struct hvec_helper<0,T>{using type=T;}; template<int D,class T>using hvec=hvec_helper<D,T>::type; template<class V>struct vec:vector<V>{ using vector<V>::vector; ll size()const{return vector<V>::size();} }; template<class...A>requires(sizeof...(A)>=2)vec(const A&...a)->vec<hvec<sizeof...(A)-2,pack_back_t<A...>>>; } namespace my{ template<class T>struct matrix:vec<vec<T>>{ ll H,W; matrix()=default; matrix(ll n):H(n),W(n){this->resize(n,vec<T>(n));} matrix(ll n,ll m,T x={}):H(n),W(m){this->resize(n,vec<T>(m,x));} matrix(const vec<vec<T>>&v):H(v.size()),W(v[0].size()){vector<vec<T>>::operator=(v);} auto&operator*=(const matrix&a){ assert(W==a.H); matrix r(H,a.W); fo(i,H)fo(k,W)fo(j,a.W)r[i][j]+=(*this)[i][k]*a[k][j]; swap(*this,r); return*this; } friend vec<T>operator*(const vec<T>&v,const matrix&a){ assert(v.size()==a.H); vec<T>r(a.W); fo(i,a.H)fo(j,a.W)r[j]+=v[i]*a[i][j]; return r; } auto pow(ll n)const{matrix e(H);fo(i,H)e[i][i]=1;return my::pow(*this,n,e);} auto transpose()const{ matrix r(W,H); fo(i,H)fo(j,W)r[j][i]=(*this)[i][j]; return r; } }; } namespace my{entry void main(){ multiple_testcases LL(N); use_ml998244353 matrix<ml>A{{ {1,1,0,0,0,0,0}, // -1 {1,1,0,0,1,1,1}, // 1 {1,1,1,1,0,0,0}, // -2 {1,1,1,1,0,0,0}, // 2 {0,0,1,1,1,1,0}, // -4 {0,0,1,1,1,1,0}, // 4 {0,0,0,0,1,1,1}, // -8 }}; A=A.pow(N); pp((vec<ml>{0,1,0,0,0,0,0}*A.transpose())[1]-ml(2).pow(N-1)); }}