結果

問題 No.978 Fibonacci Convolution Easy
ユーザー iqueue02iqueue02
提出日時 2020-01-31 22:05:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 554 bytes
コンパイル時間 1,727 ms
コンパイル使用メモリ 178,144 KB
実行使用メモリ 143,876 KB
最終ジャッジ日時 2023-10-17 09:54:03
合計ジャッジ時間 21,542 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
5,052 KB
testcase_01 AC 802 ms
58,084 KB
testcase_02 AC 367 ms
31,028 KB
testcase_03 TLE -
testcase_04 AC 481 ms
37,560 KB
testcase_05 AC 82 ms
10,436 KB
testcase_06 AC 668 ms
50,496 KB
testcase_07 AC 1,310 ms
90,684 KB
testcase_08 AC 878 ms
63,628 KB
testcase_09 AC 1,627 ms
103,620 KB
testcase_10 TLE -
testcase_11 AC 573 ms
43,104 KB
testcase_12 AC 72 ms
9,644 KB
testcase_13 AC 654 ms
49,704 KB
testcase_14 AC 170 ms
16,244 KB
testcase_15 AC 841 ms
56,500 KB
testcase_16 TLE -
testcase_17 TLE -
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;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr ll mod = 1e9+7;

int main(){
  int n;
  ll p;
  cin >> n >> p;
  map<int,ll> dp;  
  dp[1] = 0;
  dp[2] = 1;
  for (int i = 3; i <= n; i++) (dp[i] = p * dp[i-1] % mod + dp[i-2]) %= mod;
  ll res = 0;
  vector<ll> cum(n+1,0);
  rep(i,n) cum[i+1] = (cum[i] + dp[i+1]) % mod;
  for (int i = 1; i <= n; i++) (res += dp[i] * cum[i] % mod) %= mod;
  cout << res << endl;
  return 0;
}
0