結果

問題 No.1892 Extended Fib Series
ユーザー kacho65535kacho65535
提出日時 2022-05-13 15:54:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 2,456 bytes
コンパイル時間 1,962 ms
コンパイル使用メモリ 197,432 KB
実行使用メモリ 5,848 KB
最終ジャッジ日時 2023-09-28 20:06:18
合計ジャッジ時間 4,652 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
5,560 KB
testcase_01 AC 6 ms
5,600 KB
testcase_02 AC 5 ms
5,608 KB
testcase_03 AC 6 ms
5,848 KB
testcase_04 AC 5 ms
5,520 KB
testcase_05 AC 5 ms
5,528 KB
testcase_06 AC 5 ms
5,520 KB
testcase_07 AC 6 ms
5,548 KB
testcase_08 AC 6 ms
5,596 KB
testcase_09 AC 6 ms
5,740 KB
testcase_10 AC 6 ms
5,736 KB
testcase_11 AC 6 ms
5,624 KB
testcase_12 AC 6 ms
5,612 KB
testcase_13 AC 5 ms
5,596 KB
testcase_14 AC 6 ms
5,516 KB
testcase_15 AC 6 ms
5,548 KB
testcase_16 AC 6 ms
5,556 KB
testcase_17 AC 6 ms
5,616 KB
testcase_18 AC 5 ms
5,600 KB
testcase_19 AC 6 ms
5,528 KB
testcase_20 AC 5 ms
5,592 KB
testcase_21 AC 6 ms
5,528 KB
testcase_22 AC 6 ms
5,740 KB
testcase_23 AC 6 ms
5,576 KB
testcase_24 AC 5 ms
5,600 KB
testcase_25 AC 6 ms
5,736 KB
testcase_26 AC 6 ms
5,664 KB
testcase_27 AC 6 ms
5,736 KB
testcase_28 AC 6 ms
5,620 KB
testcase_29 AC 6 ms
5,600 KB
testcase_30 AC 6 ms
5,596 KB
testcase_31 AC 6 ms
5,532 KB
testcase_32 AC 5 ms
5,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define BEGIN_STACK_EXTEND(size)                                                                                  \
    void *stack_extend_memory_ = malloc(size);                                                                    \
    void *stack_extend_origin_memory_;                                                                            \
    char *stack_extend_dummy_memory_ = (char *)alloca((1 + (int)(((long long)stack_extend_memory_) & 127)) * 16); \
    *stack_extend_dummy_memory_ = 0;                                                                              \
    asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp"                                                             \
                 : "=b"(stack_extend_origin_memory_)                                                              \
                 : "a"((char *)stack_extend_memory_ + (size)-1024));
#define END_STACK_EXTEND                                                 \
    asm volatile("mov %%rax, %%rsp" ::"a"(stack_extend_origin_memory_)); \
    free(stack_extend_memory_);
#define mod 1000000007ll
#define loop(i, n) for (int i = 0; i < n; i++)
#define flagcount(bit) __builtin_popcount(bit)
#define flag(x) (1ll << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1ll << i))
#define all(v) v.begin(), v.end()
#define putout(a) cout << a << '\n'
#define Sum(v) accumulate(all(v), 0ll)
template <typename T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b; // aをbで更新
        return true;
    }
    return false;
}
template <typename T>
bool chmin(T &a, const T &b)
{
    if (a > b)
    {
        a = b; // aをbで更新
        return true;
    }
    return false;
}
void AS(ll X, ll L, ll R) { assert(L <= X && X <= R); }
ll fib[300000];
int main()
{
    // cout << fixed << setprecision(10);
    /*
    A0=1
    A1=A0=1
    Ai=A_{max(0,i-L)}+...+A_{i-1}
    A_L=A_0+....+A_{L-1}
    よって、区間和で解ける
    */
    ll N, L;
    cin >> N >> L;
    fib[0] = 1;
    ll now = 1;
    loop(i, 280000)
    {
        if ((i + 1) > L)
        {
            now -= fib[(i + 1) - L - 1];
            now += mod;
            now %= mod;
        }
        fib[i + 1] = now % mod;
        now += fib[i + 1];
        now %= mod;
    }
    putout(fib[N]);
    return 0;
}
0