結果

問題 No.978 Fibonacci Convolution Easy
ユーザー HaaHaa
提出日時 2020-01-31 22:10:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 623 bytes
コンパイル時間 1,553 ms
コンパイル使用メモリ 169,416 KB
実行使用メモリ 34,568 KB
最終ジャッジ日時 2023-10-19 01:03:26
合計ジャッジ時間 2,762 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 23 ms
15,380 KB
testcase_02 AC 13 ms
9,512 KB
testcase_03 AC 49 ms
33,316 KB
testcase_04 AC 15 ms
10,764 KB
testcase_05 AC 5 ms
4,828 KB
testcase_06 AC 19 ms
13,864 KB
testcase_07 AC 33 ms
22,568 KB
testcase_08 AC 24 ms
16,700 KB
testcase_09 AC 37 ms
25,600 KB
testcase_10 AC 50 ms
34,568 KB
testcase_11 AC 17 ms
12,084 KB
testcase_12 AC 5 ms
4,564 KB
testcase_13 AC 20 ms
13,600 KB
testcase_14 AC 8 ms
6,148 KB
testcase_15 AC 21 ms
15,116 KB
testcase_16 AC 50 ms
34,568 KB
testcase_17 AC 51 ms
34,332 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 2147483647;
const ll LINF = 9223372036854775807;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	ll n, p; cin >> n >> p;
	VI a(n); a[0] = 0; a[1] = 1;
	REP(i, n - 2)a[i + 2] = (((p * a[i + 1]) % MOD) + a[i]) % MOD;
	VI r(n + 1); r[0] = 0;
	REP(i, n)r[i + 1] = (r[i] + a[i]) % MOD;
	ll ans = 0;
	REP(i, n) {
		ans += (a[i] * r[i + 1]) % MOD;
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}
0