結果
問題 | No.1810 RGB Biscuits |
ユーザー | ytqm3 |
提出日時 | 2022-01-14 22:22:46 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 49 ms / 2,000 ms |
コード長 | 3,655 bytes |
コンパイル時間 | 2,595 ms |
コンパイル使用メモリ | 216,044 KB |
最終ジャッジ日時 | 2025-01-27 11:46:14 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
ソースコード
#include<bits/stdc++.h> typedef uint64_t u64; typedef int64_t i64; using namespace std; template<typename T> void scan_(vector<T>& a){ for(auto& v:a){ cin>>v; } } template<typename T> void scan_(T& a){ cin>>a; } void scan(){} template<typename T,class... Args> void scan(T& n,Args&... args){ scan_(n),scan(args...); } template<typename T> void println(T n){ cout<<n<<"\n"; } template<typename T,class... Args> void println(T n,Args... args){ cout<<n<<" ",println(args...); } template<typename T> void println(vector<T> v){ for(size_t i=0;i<v.size();++i){ cout<<v[i]<<" \n"[i==v.size()-1]; } } template<u64 mod> struct modint{ u64 val; modint(i64 val_=0):val((val_%i64(mod)+i64(mod))%i64(mod)){} modint operator-(){ return (val==0)?0:mod-val; } modint operator+(modint rhs){ return modint(*this)+=rhs; } modint operator-(modint rhs){ return modint(*this)-=rhs; } modint operator*(modint rhs){ return modint(*this)*=rhs; } modint operator/(modint rhs){ return modint(*this)/=rhs; } modint operator^(i64 rhs){ return modint(*this)^=rhs; } modint &operator+=(modint rhs){ val+=rhs.val,val-=((val>=mod)?mod:0); return (*this); } modint &operator-=(modint rhs){ val+=((val<rhs.val)?mod:0),val-=rhs.val; return (*this); } modint &operator*=(modint rhs){ val=val*rhs.val%mod; return (*this); } modint &operator/=(modint rhs){ return (*this)*=rhs^(mod-2); } modint &operator^=(i64 rhs){ modint res=1,now=(*this); while(rhs){ res*=((rhs&1)?now:1),now*=now,rhs>>=1; } return (*this)=res; } bool operator==(modint rhs){ return val==rhs.val; } bool operator!=(modint rhs){ return val!=rhs.val; } friend std::ostream &operator<<(std::ostream& os,modint x){ return os<<(x.val); } friend std::istream &operator>>(std::istream& is,modint& x){ u64 t; is>>t,x=t; return is; } }; template<typename T> struct matrix{ vector<vector<T>> val; int height,width; matrix(int H,int W,T init=0):val(H,vector<T> (W,init)),height(H),width(W){} matrix(vector<vector<T>> val_):val(val_),height(val_.size()),width(val_[0].size()){} vector<T> &operator[](int i){ return val[i]; } matrix operator+(matrix rhs){ return matrix(*this)+=rhs; } matrix operator*(matrix rhs){ return matrix(*this)*=rhs; } matrix operator^(i64 rhs){ return matrix(*this)^=rhs; } matrix operator+=(matrix rhs){ for(int i=0;i<rhs.height;++i){ for(int j=0;j<rhs.width;++j){ (*this)[i][j]+=rhs[i][j]; } } return (*this); } matrix operator*=(matrix rhs){ matrix<T> res(height,rhs.width,0); for(int i=0;i<this->height;++i){ for(int j=0;j<rhs.width;++j){ for(int k=0;k<this->width;++k){ res[i][j]+=(*this)[i][k]*rhs[k][j]; } } } return (*this)=res; } matrix operator^=(i64 k){ int n=(*this).height; matrix res=identity(n),now=(*this); while(k>0){ if(k%2==1){ res*=now; } now*=now; k/=2; } return (*this)=res; } matrix identity(int n){ matrix res(n,n); for(int i=0;i<n;++i){ res[i][i]=1; } return res; } }; int main(){ constexpr u64 mod=1000000007; typedef modint<mod> mint; mint A,B; scan(A,B); int N; scan(N); matrix<mint> C({{0,0,1},{1,0,0},{0,0,0}}),D(vector<vector<mint>>{{1,0,0},{0,1,0},{A,B,1}}),E(vector<vector<mint>>{{1},{1},{0}}); for(int i=0;i<N;++i){ i64 t; scan(t); auto F=((C*D)^(t/2)); if(t%2==1){ F=D*F; } F*=E; println(F[0][0]+F[1][0]+F[2][0]); } }