結果
問題 | No.1810 RGB Biscuits |
ユーザー | tnakao0123 |
提出日時 | 2022-01-15 23:25:23 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 5 ms / 2,000 ms |
コード長 | 1,926 bytes |
コンパイル時間 | 431 ms |
コンパイル使用メモリ | 45,824 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-22 05:35:26 |
合計ジャッジ時間 | 1,208 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
ソースコード
/* -*- coding: utf-8 -*- * * 1810.cc: No.1810 RGB Biscuits - yukicoder */ #include<cstdio> #include<cstring> #include<algorithm> using namespace std; /* constant */ const int MAX_N = 1000; const int MOD = 1000000007; /* typedef */ typedef long long ll; template<const int MOD> struct MI { int v; MI(): v() {} MI(int _v): v(_v % MOD) {} MI(long long _v): v(_v % MOD) {} MI operator+(const MI m) const { return MI(v + m.v); } MI operator-(const MI m) const { return MI(v + MOD - m.v); } MI operator*(const MI m) const { return MI((long long)v * m.v); } MI &operator+=(const MI m) { return (*this = *this + m); } MI &operator-=(const MI m) { return (*this = *this - m); } MI &operator*=(const MI m) { return (*this = *this * m); } }; typedef MI<MOD> mi; typedef mi mat[2][2]; /* global variables */ mat ma, mb; /* subroutines */ inline void initmat(mat a) { memset(a, 0, sizeof(mat)); } inline void unitmat(mat a) { a[0][0] = a[1][1] = 1; a[0][1] = a[1][0] = 0; } inline void copymat(const mat a, mat b) { memcpy(b, a, sizeof(mat)); } inline void mulmat(const mat a, const mat b, mat c) { for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) { c[i][j] = 0; for (int k = 0; k < 2; k++) c[i][j] += a[i][k] * b[k][j]; } } inline void powmat(const mat a, ll b, mat c) { mat s, t; copymat(a, s); unitmat(c); while (b > 0) { if (b & 1) { mulmat(c, s, t); copymat(t, c); } mulmat(s, s, t); copymat(t, s); b >>= 1; } } /* main */ int main() { int a, b, n; scanf("%d%d%d", &a, &b, &n); ma[0][0] = a, ma[0][1] = b; ma[1][0] = 1, ma[1][1] = 0; while (n--) { ll ti; scanf("%lld", &ti); powmat(ma, ti / 2, mb); mi rc = mb[0][0] + mb[0][1]; mi gc = mb[1][0] + mb[1][1]; mi bc = (ti & 1) ? rc * a + gc * b : 0; mi sum = rc + gc + bc; printf("%d\n", sum.v); } return 0; }