結果
問題 | No.978 Fibonacci Convolution Easy |
ユーザー |
![]() |
提出日時 | 2020-02-01 15:26:24 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 60 ms / 2,000 ms |
コード長 | 579 bytes |
コンパイル時間 | 1,729 ms |
コンパイル使用メモリ | 168,648 KB |
実行使用メモリ | 34,560 KB |
最終ジャッジ日時 | 2024-09-18 21:06:27 |
合計ジャッジ時間 | 2,968 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
ソースコード
#include<bits/stdc++.h> using namespace std; #ifdef LOCAL_DEBUG #include "LOCAL_DEBUG.hpp" #endif #define int long long const int MOD = 1e9 + 7; signed main(){ int n, p; cin >> n >> p; vector<int> dp(n+1); dp[1] = 0, dp[2] = 1; for(int i = 3; i <= n; i++){ dp[i] = p * dp[i-1] + dp[i-2]; dp[i] %= MOD; } vector<int> imos(n+2, 0); for(int i = 0; i <= n; i++){ imos[i+1] = imos[i] + dp[i]; imos[i+1] %= MOD; } int ans = 0; for(int i = 1; i <= n; i++){ ans = (ans + dp[i] * imos[i+1]) % MOD; } cout << ans << endl; return 0; }