Submission #1797389


Source Code Expand

#include <iostream>
#include <cstdio>

typedef long long ll;

using namespace std;

#define MAX_N 1000000
#define MAX_K 1000000
#define mod(x, y) ((x % y) + y) % y
#define MOD 1000000007
#define modp(x) mod(x, MOD)

int main(int argc, const char * argv[]) {
    // a[i] : 駅1から駅iまでの停まり方(駅iには必ず止まる)の総数
    ll a[MAX_N];
    // b[i] : 駅1から駅iまでの停まり方(駅iには止まらない)の総数
    ll b[MAX_N];
    
    int N, K;
    cin >> N >> K;
    
    a[1] = 1;
    b[1] = 0;
    for (int i = 1; i < K-1; i++) {
        a[i+1] = modp(a[i] + b[i]);
        b[i+1] = modp(a[i] + b[i]);
    }
    
    a[K] = modp(a[K-1] + b[K-1] - 1);
    b[K] = modp(a[K-1] + b[K-1]);
    
    for (int i = K; i < N; i++) {
        a[i+1] = modp((a[i] - b[i-(K-1)]) + b[i]);
        b[i+1] = modp((a[i] - b[i-(K-1)]) + b[i] + b[i-(K-1)]);
    }
    cout << a[N] << endl;
    return 0;
}

Submission Info

Submission Time
Task F - 準急
User habara_k
Language C++14 (GCC 5.4.1)
Score 4
Code Size 965 Byte
Status AC
Exec Time 11 ms
Memory 15872 KB

Judge Result

Set Name All
Score / Max Score 4 / 4
Status
AC × 7
Set Name Test Cases
All 00, 01, 02, 03, 04, 90, 91
Case Name Status Exec Time Memory
00 AC 11 ms 15872 KB
01 AC 10 ms 15872 KB
02 AC 6 ms 9856 KB
03 AC 5 ms 7936 KB
04 AC 10 ms 15616 KB
90 AC 2 ms 2304 KB
91 AC 2 ms 2304 KB