結果
問題 | No.1879 How many matchings? |
ユーザー |
|
提出日時 | 2022-03-17 17:27:51 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,058 bytes |
コンパイル時間 | 1,166 ms |
コンパイル使用メモリ | 90,172 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-01 14:20:24 |
合計ジャッジ時間 | 1,726 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 15 |
ソースコード
#include <cassert>#include <iostream>#include <vector>#include <atcoder/modint>using Mint = atcoder::modint1000000007;struct Mat{Mint a[2][2];Mat(){for (int i = 0; i < 2; ++i)for (int j = 0; j < 2; ++j)a[i][j] = 0;}};Mat I(){Mat c;c.a[0][0] = c.a[1][1] = 1;return c;}Mat F(){Mat c;c.a[0][0] = c.a[0][1] = c.a[1][0] = 1;return c;}Mat mul(Mat a, Mat b){Mat c{};for (int i = 0; i < 2; ++i)for (int j = 0; j < 2; ++j)for (int k = 0; k < 2; ++k)c.a[i][k] += a.a[i][j] * b.a[j][k];return c;}Mat pow(Mat a, long long b){if (b == 0)return I();Mat r = pow(a, b / 2);r = mul(r, r);if (b & 1)r = mul(r, a);return r;}Mint f(long long n){if (n == 0)return 0;auto ret = pow(F(), n - 1);return ret.a[1][0] + ret.a[1][1];}Mint g(long long n){return (2 * n * f(n + 1) - (n + 1) * f(n)) / 5;}using namespace std;int main(){long long N;cin >> N;if (N % 2 == 0)cout << f(N / 2 + 1).val() << endl;elsecout << (g(N / 2 + 2) + g(N / 2 + 1)).val() << endl;}