結果

問題 No.978 Fibonacci Convolution Easy
ユーザー uryo1903uryo1903
提出日時 2020-01-31 22:26:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 1,405 bytes
コンパイル時間 1,586 ms
コンパイル使用メモリ 169,272 KB
実行使用メモリ 34,556 KB
最終ジャッジ日時 2023-10-19 01:03:55
合計ジャッジ時間 2,825 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 19 ms
15,368 KB
testcase_02 AC 12 ms
9,500 KB
testcase_03 AC 42 ms
33,304 KB
testcase_04 AC 13 ms
10,752 KB
testcase_05 AC 5 ms
4,816 KB
testcase_06 AC 18 ms
13,852 KB
testcase_07 AC 29 ms
22,556 KB
testcase_08 AC 21 ms
16,688 KB
testcase_09 AC 31 ms
25,588 KB
testcase_10 AC 43 ms
34,556 KB
testcase_11 AC 16 ms
12,072 KB
testcase_12 AC 5 ms
4,552 KB
testcase_13 AC 17 ms
13,588 KB
testcase_14 AC 7 ms
6,136 KB
testcase_15 AC 18 ms
15,104 KB
testcase_16 AC 43 ms
34,556 KB
testcase_17 AC 43 ms
34,320 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;
  
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(14)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 
constexpr int MOD = 998244353;
 
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
 
template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A,class B> using umap = unordered_map<A,B>;
   
int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n,p;
    cin >> n >> p;
    vector<int> a(n+5),cum(n+5);
    a[1] = 0;
    a[2] = 1;
    cum[1] = 0;
    cum[2] = 1;

    for(int i = 3;i <= n;++i){
        (a[i] = p * a[i-1]) %= mod;
        (a[i] += a[i-2]) %= mod;
        cum[i] = a[i];
        (cum[i] += cum[i-1]) %= mod;
    }

    int res = 0;
    reps(i,n){
        int tmp = a[i] * cum[i] % mod;
        (res += tmp) %= mod;
    }

    cout << res << '\n';

    return 0;
}
0