結果
| 問題 |
No.3228 Very Large Fibonacci Sum
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-10-15 16:40:47 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,337 bytes |
| コンパイル時間 | 6,278 ms |
| コンパイル使用メモリ | 335,164 KB |
| 実行使用メモリ | 7,720 KB |
| 最終ジャッジ日時 | 2025-10-15 16:40:54 |
| 合計ジャッジ時間 | 6,202 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using mint = modint1000000007;
template<typename T>
struct Matrix {
int h, w;
vector<vector<T>> d;
Matrix() {}
Matrix(int h, int w, T val=0): h(h), w(w), d(h, vector<T>(w,val)) {}
Matrix& unit() {
assert(h == w);
rep(i,h) d[i][i] = 1;
return *this;
}
const vector<T>& operator[](int i) const { return d[i];}
vector<T>& operator[](int i) { return d[i];}
Matrix operator*(const Matrix& a) const {
assert(w == a.h);
Matrix r(h, a.w);
rep(i,h)rep(k,w)rep(j,a.w) {
r[i][j] += d[i][k]*a[k][j];
}
return r;
}
Matrix pow(long long t) const {
assert(h == w);
if (!t) return Matrix(h,h).unit();
if (t == 1) return *this;
Matrix r = pow(t>>1);
r = r*r;
if (t&1) r = r*(*this);
return r;
}
};
int main() {
ll a, b, c, d, e, n;
cin >> a >> b >> c >> d >> e >> n;
Matrix<mint> A(4, 4), x(4, 1);
x[0][0] = (a+b)+(c*b+d*a+e);
x[1][0] = a+b;
x[2][0] = a;
x[3][0] = 1;
A[0][0] = c+1; A[0][1] = d-c; A[0][2] = -d; A[0][3] = e;
A[1][0] = A[2][1] = A[3][3] = 1;
x = A.pow(n)*x;
mint ans = x[2][0];
cout << ans.val() << '\n';
return 0;
}