結果

問題 No.1810 RGB Biscuits
ユーザー eve__fuyuki
提出日時 2024-04-02 13:54:38
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 1,463 bytes
コンパイル時間 2,380 ms
コンパイル使用メモリ 206,632 KB
最終ジャッジ日時 2025-02-20 19:39:05
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/modint>
using namespace std;
using mint = atcoder::modint1000000007;

using vec = vector<mint>;
using mat = vector<vec>;
vec mul(mat a, vec b) {
    vec c(a.size());
    for (int i = 0; i < a.size(); i++) {
        for (int j = 0; j < b.size(); j++) {
            c[i] += a[i][j] * b[j];
        }
    }
    return c;
}
mat mul(mat a, mat b) {
    mat c(a.size(), vec(b[0].size()));
    for (int i = 0; i < a.size(); i++) {
        for (int j = 0; j < b.size(); j++) {
            for (int k = 0; k < b[0].size(); k++) {
                c[i][k] += a[i][j] * b[j][k];
            }
        }
    }
    return c;
}
mat mat_pow(mat a, long long n) {
    mat res(a.size(), vec(a.size()));
    for (int i = 0; i < a.size(); i++) {
        res[i][i] = 1;
    }
    while (n) {
        if (n & 1) res = mul(res, a);
        a = mul(a, a);
        n >>= 1;
    }
    return res;
}
void fast_io() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
}

int main() {
    fast_io();
    int a, b;
    cin >> a >> b;
    mat A = {{a, b}, {1, 0}};
    int n;
    cin >> n;
    for (; n--;) {
        long long t;
        cin >> t;
        auto res = mul(mat_pow(A, t / 2), vec{1, 1});
        if (t % 2 == 0) {
            mint ans = res[0] + res[1];
            cout << ans.val() << "\n";
        } else {
            mint ans = (a + 1) * res[0] + (b + 1) * res[1];
            cout << ans.val() << "\n";
        }
    }
}
0