結果
| 問題 | 
                            No.1810 RGB Biscuits
                             | 
                    
| コンテスト | |
| ユーザー | 
                             kokatsu
                         | 
                    
| 提出日時 | 2022-01-14 22:56:21 | 
| 言語 | D  (dmd 2.109.1)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 40 ms / 2,000 ms | 
| コード長 | 1,173 bytes | 
| コンパイル時間 | 2,291 ms | 
| コンパイル使用メモリ | 206,484 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-22 14:04:11 | 
| 合計ジャッジ時間 | 3,524 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 20 | 
ソースコード
import std;
void main() {
    long A, B, N;
    readf("%d %d\n%d\n", A, B, N);
    long M = 10 ^^ 9 + 7;
    long[][] X = [
        [A, B],
        [1L, 0L]
    ];
    foreach (_; 0 .. N) {
        long T;
        readf("%d\n", T);
        auto Y = matPowMod(X, T/2, M);
        long c = Y[0].sum, d = Y[1].sum;
        long res = (c + d) % M;
        if (T & 1) res = (res + A * c + B * d) % M;
        res.writeln;
    }
}
long[][] matMulMod(long[][] a, long[][] b, long m) {
    long l = a[0].length.to!long;
    assert(l == b.length);
    auto res = new long[][](a.length, b[0].length);
    foreach (i, r; res) {
        foreach (k; 0 .. l) {
            foreach (j, ref e; r) {
                e = (e + a[i][k] * b[k][j]) % m;
            }
        }
    }
    return res;
}
long[][] matPowMod(long[][] mat, long p, long m) {
    long l = mat[0].length.to!long;
    assert(l == mat.length);
    auto res = new long[][](l, l);
    foreach (i; 0 .. l) {
        res[i][i] = 1;
    }
    while (p > 0) {
        if (p & 1) {
            res = matMulMod(res, mat, m);
        }
        mat = matMulMod(mat, mat, m);
        p >>= 1;
    }
    return res;
}
            
            
            
        
            
kokatsu