結果
問題 | No.891 隣接3項間の漸化式 |
ユーザー |
![]() |
提出日時 | 2024-04-24 21:20:06 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,029 bytes |
コンパイル時間 | 2,613 ms |
コンパイル使用メモリ | 209,712 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-07 06:25:56 |
合計ジャッジ時間 | 4,145 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 35 WA * 4 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/modint> using namespace std; using mint = atcoder::modint1000000007; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } using vec = vector<mint>; using mat = vector<vec>; mat mul(const mat& a, const mat& b) { int n = a.size(); int m = b.size(); int k = b[0].size(); mat c(n, vec(k)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { for (int l = 0; l < k; l++) { c[i][l] += a[i][j] * b[j][l]; } } } return c; } mat pow(mat a, long long n) { int m = a.size(); mat res(m, vec(m)); for (int i = 0; i < m; i++) { res[i][i] = 1; } while (n > 0) { if (n & 1) { res = mul(res, a); } a = mul(a, a); n >>= 1; } return res; } int main() { fast_io(); int a, b, n; cin >> a >> b >> n; mat A = {{a, b}, {1, 0}}; auto B = pow(A, n - 1); cout << B[0][0].val() << '\n'; }