結果

問題 No.1810 RGB Biscuits
ユーザー asaringoasaringo
提出日時 2022-01-15 15:20:27
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 1,812 bytes
コンパイル時間 1,956 ms
コンパイル使用メモリ 176,952 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-13 22:29:26
合計ジャッジ時間 3,452 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 27 ms
4,376 KB
testcase_06 AC 28 ms
4,380 KB
testcase_07 AC 29 ms
4,380 KB
testcase_08 AC 29 ms
4,376 KB
testcase_09 AC 29 ms
4,380 KB
testcase_10 AC 19 ms
4,380 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 6 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 15 ms
4,376 KB
testcase_18 AC 15 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 4 ms
4,376 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 ;

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