Submission #1452948


Source Code Expand

#include <bits/stdc++.h>


using namespace std;


// Powered by caide (code generator, tester, and library code inliner)

int n, k;
const int INF = 1e9 + 7;

static int dp[1000003];

class Solution {
public:

  int dfs(int now)
  {
    if (now >= n - 1) {
      return now <= n + 1;
    }
    if (~dp[now]) return dp[now];

    int res = 0;
    
    for (int i = !now; i < k; i++) {
      if (now + i != n - 1) {
        res += dfs(now + i + 1);
      }
      res %= INF;
    }
    return dp[now] = res;
  }

  void solve(std::istream& in, std::ostream& out)
  {
    memset(dp, -1, sizeof dp);
    in >> n >> k;
    out << dfs(0) << "\n";
  }
};

void solve(std::istream& in, std::ostream& out)
{
  out << std::setprecision(12);
  Solution solution;
  solution.solve(in, out);
}


#include <fstream>
#include <iostream>


int main() {
  
  ios_base::sync_with_stdio(0);
  cin.tie(0);


  istream& in = cin;


  ostream& out = cout;

  solve(in, out);
  return 0;
}


Submission Info

Submission Time
Task F - 準急
User stone725
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1037 Byte
Status TLE
Exec Time 2105 ms
Memory 32256 KB

Judge Result

Set Name All
Score / Max Score 0 / 4
Status
AC × 4
TLE × 3
Set Name Test Cases
All 00, 01, 02, 03, 04, 90, 91
Case Name Status Exec Time Memory
00 AC 26 ms 32256 KB
01 TLE 2105 ms 32256 KB
02 TLE 2104 ms 17024 KB
03 TLE 2104 ms 13312 KB
04 AC 101 ms 30208 KB
90 AC 3 ms 4224 KB
91 AC 2 ms 4224 KB