結果

問題 No.1810 RGB Biscuits
ユーザー HaaHaa
提出日時 2022-01-14 21:56:11
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 1,316 bytes
コンパイル時間 2,023 ms
コンパイル使用メモリ 176,240 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-12 19:23:59
合計ジャッジ時間 3,249 ms
ジャッジサーバーID
(参考情報)
judge14 / judge10
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 41 ms
4,384 KB
testcase_06 AC 45 ms
4,380 KB
testcase_07 AC 44 ms
4,380 KB
testcase_08 AC 44 ms
4,380 KB
testcase_09 AC 43 ms
4,380 KB
testcase_10 AC 28 ms
4,380 KB
testcase_11 AC 4 ms
4,380 KB
testcase_12 AC 3 ms
4,384 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 9 ms
4,384 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 4 ms
4,380 KB
testcase_17 AC 22 ms
4,380 KB
testcase_18 AC 23 ms
4,384 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 6 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
template<typename T> bool chmax(T &x, const T &y) {return (x<y)?(x=y,true):false;};
template<typename T> bool chmin(T &x, const T &y) {return (x>y)?(x=y,true):false;};
constexpr ll MOD=1000000007;
constexpr ll INF=2e18;

VVI matmult(VVI a, VVI b){
    int p=a.size(), q=b[0].size(), r=a[0].size();
    VVI ret(p,VI(q));
    REP(i,p)REP(j,q){
        ll sum=0;
        REP(k,r){
            sum=(sum+a[i][k]*b[k][j]%MOD)%MOD;
        }
        ret[i][j]=sum;
    }
    return ret;
}

VVI matpower(VVI x, ll y){
    int n=x.size();
    VVI ret(n,VI(n,0));
    REP(i,n) ret[i][i]=1;
    while(y){
        if(y&1) ret=matmult(ret,x);
        x=matmult(x,x);
        y>>=1;
    }
    return ret;
}

int main(){
    ll a, b; cin >> a >> b;
    VVI x={{1,0,0},{0,1,0},{a,b,1}};
    VVI y={{0,0,1},{1,0,0},{0,0,0}};
    VVI z=matmult(y,x);
    int n; cin >> n;
    ll t;
    REP(i,n){
        cin >> t;
        VVI m=matpower(z,t/2);
        if(t%2==1)
            m=matmult(x,m);
        VVI a={{1},{1},{0}};
        a=matmult(m,a);
        cout << (a[0][0]+a[1][0]+a[2][0])%MOD << endl;
    }
    return 0;
}
0