結果

問題 No.1810 RGB Biscuits
ユーザー asaringoasaringo
提出日時 2022-01-15 15:18:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 1,791 bytes
コンパイル時間 1,881 ms
コンパイル使用メモリ 180,888 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-01 12:09:19
合計ジャッジ時間 2,430 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 24 ms
6,940 KB
testcase_06 AC 26 ms
6,940 KB
testcase_07 AC 26 ms
6,940 KB
testcase_08 AC 26 ms
6,944 KB
testcase_09 AC 26 ms
6,940 KB
testcase_10 AC 17 ms
6,940 KB
testcase_11 AC 3 ms
6,944 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 6 ms
6,944 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 3 ms
6,940 KB
testcase_17 AC 13 ms
6,940 KB
testcase_18 AC 14 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 1 ms
6,940 KB
testcase_21 AC 4 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef long double ld ;
typedef pair<ll,ll> P ;
typedef tuple<bool,ll,ll,ll> TP ;
#define chmin(a,b) a = min(a,b)
#define chmax(a,b) a = max(a,b)
#define bit_count(x) __builtin_popcountll(x)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a / gcd(a,b) * b
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define rrep(i,a,b) for(int i = a ; i < b ; i++)
#define endl "\n"

const int mod = 1000000007 ;

// vector<vector<ll>> A(101,vector<ll>(101)) ;

struct MATRIX{
    vector<vector<ll>> mat ;
    // 引数 : 答えになるベクトル , (vector<vector<ll>>でないことに注意)
    MATRIX(vector<ll> X){
        mat.resize(X.size(),vector<ll>(1)) ;
        rep(i,X.size()) mat[i][0] = X[i] ;
    }
    // A * B
    vector<vector<ll>> calculation(vector<vector<ll>> X , vector<vector<ll>> Y){
        int x = X.size() , y = Y[0].size() , n = Y.size() ;
        vector<vector<ll>> res(x,vector<ll>(y)) ;
        rep(i,x) rep(j,y) rep(k,n) {
            (res[i][j] += X[i][k] * Y[k][j]) %= mod ;
        }
        return res ;
    }

    void dynamic(vector<vector<ll>> A , ll k){
        int n = A.size() ;
        while(k > 0){
            if(k & 1) mat = calculation(A,mat) ;
            A = calculation(A,A) ;
            k >>= 1 ;
        }
    }

    inline ll operator [] (int i) { return mat[i][0] ; }
};

ll a , b , n ;

int main(){
    cin >> a >> b >> n ;
    vector<vector<ll>> A = {{a,b},{1,0}} ;
    vector<ll> X = {1,1} ;
    rep(i,n){
        ll t ;
        cin >> t ;
        ll s = t / 2 ;
        MATRIX mat(X) ;
        mat.dynamic(A,s) ;
        ll v = t % 2 == 0 ? 0 : (mat[0] * a % mod + mat[1] * b % mod) % mod ;
        ll res = (mat[0] + mat[1] + v) % mod ;
        cout << res << endl ;
    }
}
0