結果
問題 | No.720 行列のできるフィボナッチ数列道場 (2) |
ユーザー | potoooooooo |
提出日時 | 2018-07-28 00:15:37 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,748 bytes |
コンパイル時間 | 1,806 ms |
コンパイル使用メモリ | 166,596 KB |
実行使用メモリ | 4,384 KB |
最終ジャッジ日時 | 2023-09-19 04:45:28 |
合計ジャッジ時間 | 2,955 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,380 KB |
testcase_01 | AC | 2 ms
4,380 KB |
testcase_02 | AC | 2 ms
4,380 KB |
testcase_03 | AC | 2 ms
4,376 KB |
testcase_04 | AC | 2 ms
4,380 KB |
testcase_05 | AC | 2 ms
4,380 KB |
testcase_06 | AC | 2 ms
4,380 KB |
testcase_07 | AC | 2 ms
4,380 KB |
testcase_08 | AC | 2 ms
4,380 KB |
testcase_09 | AC | 1 ms
4,376 KB |
testcase_10 | AC | 2 ms
4,380 KB |
testcase_11 | AC | 1 ms
4,380 KB |
testcase_12 | AC | 2 ms
4,376 KB |
testcase_13 | AC | 1 ms
4,384 KB |
testcase_14 | AC | 2 ms
4,376 KB |
testcase_15 | AC | 2 ms
4,380 KB |
testcase_16 | AC | 2 ms
4,380 KB |
testcase_17 | AC | 2 ms
4,376 KB |
testcase_18 | AC | 1 ms
4,380 KB |
testcase_19 | AC | 1 ms
4,380 KB |
testcase_20 | AC | 2 ms
4,380 KB |
testcase_21 | AC | 2 ms
4,380 KB |
testcase_22 | AC | 1 ms
4,380 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #define mod 1000000007 int main(){ long long n, m; cin >> n >> m; long long a[2][2] = {{1, 1}, {1, 0}}; long long ans[2] = {1, 0}; long long ma[2][2] = {{1, 1}, {1, 0}}; m--; while (m != 0) { if (m % 2) { long long tmp[2][2] = {0}; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { tmp[i][j] = 0; for (int k = 0; k < 2; k++) { tmp[i][j] += ma[i][k] * a[k][j]; tmp[i][j] %= mod; } } } swap(ma, tmp); } long long b[2][2] = {0}; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { b[i][j] = 0; for (int k = 0; k < 2; k++) { b[i][j] += a[i][k] * a[k][j]; b[i][j] %= mod; } } } swap(a, b); m /= 2; } long long s[4][4] = {{1, 0, 1, 0}, {0, 1, 0, 1}, {1, 0, 0, 0}, {0, 1, 0, 1}}; long long u[4][4] = {{1, 0, ma[0][0], ma[0][1]}, {0, 1, ma[1][0], ma[1][1]}, {0, 0, ma[0][0], ma[0][1]}, {0, 0, ma[1][0], ma[1][1]}}; while (n != 0) { if (n % 2) { long long tmp[4][4] = {0}; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { tmp[i][j] = 0; for (int k = 0; k < 4; k++) { tmp[i][j] += u[i][k] * s[k][j]; tmp[i][j] %= mod; } } } swap(s, tmp); } long long b[4][4] = {0}; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { b[i][j] = 0; for (int k = 0; k < 4; k++) { b[i][j] += u[i][k] * u[k][j]; b[i][j] %= mod; } } } swap(u, b); n /= 2; } cout << s[1][0] << endl; return 0; }