結果

問題 No.978 Fibonacci Convolution Easy
ユーザー pointNpointN
提出日時 2020-02-25 12:27:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 981 bytes
コンパイル時間 876 ms
コンパイル使用メモリ 116,236 KB
実行使用メモリ 34,464 KB
最終ジャッジ日時 2024-04-21 13:11:34
合計ジャッジ時間 1,901 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 16 ms
15,368 KB
testcase_02 AC 9 ms
9,344 KB
testcase_03 AC 34 ms
33,152 KB
testcase_04 AC 11 ms
10,880 KB
testcase_05 AC 4 ms
5,376 KB
testcase_06 AC 13 ms
13,696 KB
testcase_07 AC 25 ms
22,640 KB
testcase_08 AC 17 ms
16,552 KB
testcase_09 AC 26 ms
25,488 KB
testcase_10 AC 36 ms
34,412 KB
testcase_11 AC 12 ms
12,032 KB
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 14 ms
13,500 KB
testcase_14 AC 6 ms
6,144 KB
testcase_15 AC 15 ms
14,976 KB
testcase_16 AC 36 ms
34,464 KB
testcase_17 AC 35 ms
34,372 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  ll N; cin >> N;
  ll p; cin >> p;
  vector<ll> fib(N);
  fib[0] = 0; fib[1] = 1;
  for(int i=2; i<N; i++){
    fib[i]=(fib[i-1]*p+fib[i-2])%mod;
  }
  vector<ll> sums(N+1,0);
  rep(i,N) sums[i+1] = (sums[i] + fib[i])%mod;
  ll ans = 0;
  rep(i,N){
    ans += fib[i]*sums[i+1];
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}
0