結果
問題 | No.1810 RGB Biscuits |
ユーザー | ytqm3 |
提出日時 | 2022-01-14 22:22:46 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 47 ms / 2,000 ms |
コード長 | 3,655 bytes |
コンパイル時間 | 2,830 ms |
コンパイル使用メモリ | 222,512 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-20 11:47:00 |
合計ジャッジ時間 | 4,224 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,820 KB |
testcase_02 | AC | 2 ms
6,816 KB |
testcase_03 | AC | 2 ms
6,816 KB |
testcase_04 | AC | 3 ms
6,816 KB |
testcase_05 | AC | 42 ms
6,816 KB |
testcase_06 | AC | 45 ms
6,820 KB |
testcase_07 | AC | 45 ms
6,816 KB |
testcase_08 | AC | 45 ms
6,816 KB |
testcase_09 | AC | 47 ms
6,816 KB |
testcase_10 | AC | 29 ms
6,820 KB |
testcase_11 | AC | 5 ms
6,816 KB |
testcase_12 | AC | 3 ms
6,820 KB |
testcase_13 | AC | 3 ms
6,816 KB |
testcase_14 | AC | 10 ms
6,816 KB |
testcase_15 | AC | 3 ms
6,820 KB |
testcase_16 | AC | 4 ms
6,816 KB |
testcase_17 | AC | 23 ms
6,816 KB |
testcase_18 | AC | 24 ms
6,820 KB |
testcase_19 | AC | 2 ms
6,820 KB |
testcase_20 | AC | 2 ms
6,820 KB |
testcase_21 | AC | 7 ms
6,820 KB |
ソースコード
#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]); } }