結果

問題 No.978 Fibonacci Convolution Easy
ユーザー CleyLCleyL
提出日時 2020-01-31 22:51:15
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 501 bytes
コンパイル時間 505 ms
コンパイル使用メモリ 64,664 KB
実行使用メモリ 34,904 KB
最終ジャッジ日時 2023-10-19 01:06:03
合計ジャッジ時間 1,615 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,880 KB
testcase_01 AC 17 ms
18,660 KB
testcase_02 AC 10 ms
12,516 KB
testcase_03 AC 39 ms
34,264 KB
testcase_04 AC 12 ms
14,564 KB
testcase_05 AC 5 ms
8,420 KB
testcase_06 AC 15 ms
16,612 KB
testcase_07 AC 25 ms
26,852 KB
testcase_08 AC 18 ms
18,660 KB
testcase_09 AC 28 ms
28,900 KB
testcase_10 AC 39 ms
34,872 KB
testcase_11 AC 13 ms
14,564 KB
testcase_12 AC 4 ms
8,420 KB
testcase_13 AC 15 ms
16,612 KB
testcase_14 AC 7 ms
10,468 KB
testcase_15 AC 16 ms
18,660 KB
testcase_16 AC 39 ms
34,904 KB
testcase_17 AC 39 ms
34,856 KB
testcase_18 AC 3 ms
5,704 KB
testcase_19 AC 2 ms
5,704 KB
testcase_20 AC 2 ms
5,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;
#define MOD 1000000007
long long memo[2000001];
long long memo2[2000002];
int main(){
  int n,p;cin>>n>>p;
  memo[1] = 0;
  memo[2] = 1;
  for(int i = 3; n >= i; i++){
    memo[i] = (p*memo[i-1]+memo[i-2])%MOD;
  }
  memo2[0] = 0;
  memo2[1] = memo[1];
  for(int i = 2; n >= i; i++){
    memo2[i] = (memo2[i-1]+memo[i])%MOD;
  }

  long long ans = 0;
  for(int i = 1; n >= i; i++){
    ans = (ans+memo[i]*(memo2[i]-memo2[0]))%MOD;
  }
  cout << ans << endl;

}
0