結果

問題 No.1879 How many matchings?
ユーザー 👑 colognecologne
提出日時 2022-03-17 17:27:51
言語 C++23(draft)
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,058 bytes
コンパイル時間 1,303 ms
コンパイル使用メモリ 91,836 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 02:29:11
合計ジャッジ時間 2,338 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,948 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,948 KB
testcase_08 AC 2 ms
6,948 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,948 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 2 ms
6,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
	else
		cout << (g(N / 2 + 2) + g(N / 2 + 1)).val() << endl;
}
0