結果

問題 No.1810 RGB Biscuits
ユーザー hourenhouren
提出日時 2022-01-14 22:57:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 1,442 bytes
コンパイル時間 2,304 ms
コンパイル使用メモリ 176,576 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-12 21:40:00
合計ジャッジ時間 3,206 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 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,380 KB
testcase_05 AC 38 ms
4,380 KB
testcase_06 AC 42 ms
4,376 KB
testcase_07 AC 41 ms
4,376 KB
testcase_08 AC 40 ms
4,380 KB
testcase_09 AC 41 ms
4,384 KB
testcase_10 AC 27 ms
4,380 KB
testcase_11 AC 4 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 8 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 21 ms
4,384 KB
testcase_18 AC 21 ms
4,380 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;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool chmax(T&a, const T&b){if(a<b){a=b;return 1;}return 0;}
const ll MOD = 1000000007;
template <typename T>
vector<vector<T>> MatrixProduct(vector<vector<T>> vec1, vector<vector<T>> vec2){
    int N = vec1.size(), M = vec2[0].size(), L = vec2.size();
    vector<vector<T>> res(N,vector<T>(M,0));
    rep(i,N) rep(j,M) rep(k,L) res[i][j] = (res[i][j] + vec1[i][k] * vec2[k][j])%MOD;
    return res;
}
int main(){
    ll a,b,n;
    cin >> a >> b >> n;
    rep(i,n){
        vector<vector<ll>> o = {
            {1,0,0},
            {0,1,0},
            {a,b,1}
        };
        vector<vector<ll>> e = {
            {0,0,1},
            {1,0,0},
            {0,0,0}
        };
        auto oe = MatrixProduct(e,o);
        vector<vector<ll>> cookie = {{1},{1},{0}};
        ll t;
        cin >> t;
        bool b = t%2;
        t >>= 1;
        while(t){
            if(t&1) cookie = MatrixProduct(oe, cookie);
            t >>= 1;
            oe = MatrixProduct(oe,oe);
        }
        if(b) cookie = MatrixProduct(o, cookie);
        ll ans = 0;
        rep(i,3){
            ans = (ans + cookie[i][0]) % MOD;
        }
        cout << ans << endl;
    }
    return 0;
}
0