結果

問題 No.978 Fibonacci Convolution Easy
ユーザー seriru13seriru13
提出日時 2020-01-31 23:00:05
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 1,135 bytes
コンパイル時間 2,175 ms
コンパイル使用メモリ 203,944 KB
実行使用メモリ 34,580 KB
最終ジャッジ日時 2023-10-19 01:06:33
合計ジャッジ時間 3,256 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 18 ms
15,392 KB
testcase_02 AC 12 ms
9,524 KB
testcase_03 AC 41 ms
33,328 KB
testcase_04 AC 13 ms
10,776 KB
testcase_05 AC 5 ms
4,840 KB
testcase_06 AC 17 ms
13,876 KB
testcase_07 AC 28 ms
22,580 KB
testcase_08 AC 20 ms
16,712 KB
testcase_09 AC 30 ms
25,612 KB
testcase_10 AC 41 ms
34,580 KB
testcase_11 AC 15 ms
12,096 KB
testcase_12 AC 4 ms
4,576 KB
testcase_13 AC 16 ms
13,612 KB
testcase_14 AC 7 ms
6,160 KB
testcase_15 AC 18 ms
15,128 KB
testcase_16 AC 41 ms
34,580 KB
testcase_17 AC 41 ms
34,344 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 ll;
#define inf 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

long long MOD(long long val, long long m) {
  long long res = val % m;
  if (res < 0) res += m;
  return res;
}

int main() {
  ll n, p;
  cin >> n >> p;
  vector<ll> f(n), sum(n+1);
  f[0] = 0, f[1] = 1;
  sum[0] = 0, sum[1] = 0, sum[2] = 1;
  for (int i = 2; i < n; ++i) {
    f[i] = p*f[i-1] + f[i-2];
    f[i] %= mod;
    sum[i+1] += f[i] + sum[i];
    sum[i+1] %= mod;
  }

  ll ans = 0;
  rep(i, n) {
    ll tmp = MOD((sum[n] % mod) - (sum[i] % mod), mod);
    tmp *= f[i];
    tmp %= mod;
    ans += tmp;
    ans %= mod;
  }

  cout << ans << endl;
}
0