Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#ifdef DEBUG
#include "../../lib/utils.cpp"
#endif
#include <bits/stdc++.h>

using namespace std;
using ll = int64_t;
#define int int64_t
#define INF 10e9

/* ==== declarations ====== */
// functions
void solve();
void getInput();

// global variables
int K;
string S;
int N;
vector<vector<int>> dp;

template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 value;

  constexpr modint(const u64 x = 0) noexcept : value(x % Modulus) {
    // cout<<"constructor is called"<<endl;
  }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    value += rhs.value;
    if (value >= Modulus) {
      value -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (value < rhs.value) {
      value += Modulus;
    }
    value -= rhs.value;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    value = value * rhs.value % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    if (value % rhs.value != 0) {
      cout << "modint error!: cannnot divide value (" << value << ") by ("
           << rhs.value << ")" << endl;
      exit(1);
    }
    value = value / rhs.value;
    return *this;
  }

  constexpr modint pow(int64_t t) noexcept {
    if (t == 0)
      return 1;
    modint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }
  constexpr modint inv() noexcept { return pow(Modulus - 2); }
  friend std::istream &operator>>(std::istream &is, modint &x) {
    u64 t;
    is >> t;
    x = modint(t);
    return is;
  }
  friend std::ostream &operator<<(std::ostream &os, const modint &x) {
    os << x.value;
    return os;
  }

  static modint calcPermutation(int64_t n, int64_t r) {
    modint res = 1;
    for (int64_t i = 0; i < r; ++i) {
      res *= (n - i);
    }
    return res;
  }

  static modint calcCombination(int64_t n, int64_t r) {
    assert(n < Modulus);
    static vector<modint> factorial, factorial_inv;
    if (factorial.size() == 0) {
      int maxsize = 2000000;
      factorial.resize(maxsize);
      factorial_inv.resize(maxsize);
      factorial[0] = 1;
      for (int i = 1; i <= maxsize; ++i)
        factorial[i] = factorial[i - 1] * i;
      factorial_inv[maxsize] = factorial[maxsize].inv();
      for (int i = maxsize; i >= 1; --i)
        factorial_inv[i - 1] = factorial_inv[i] * i;
    }
    return factorial[n] * factorial_inv[r] * factorial_inv[n - r];
  }
};

void getInput() {
  cin >> K;
  cin >> S;
  N = K + S.size();
}

void solve() {
  using mi = modint<1000000007>;
  mi total;
  for (int i = S.size(); i < N + 1; ++i) {
    auto numCombs = mi::calcCombination(i - 1, S.size() - 1);
    int fp = i - S.size();
    int lp = N - i;
    auto score = mi(25).pow(fp) * numCombs * mi(26).pow(lp);
    total += score;
  }
  cout << total << endl;
}

signed main() {
  getInput();
  solve();

  return 0;
}


Error: 0

Fixed submission:

#ifdef DEBUG
#include "utils.cpp"
#endif
#include <bits/stdc++.h>

using namespace std;
using ll = int64_t;
#define int int64_t
#define INF 10e9

/* ==== declarations ====== */
// functions
void solve();
void getInput();

// global variables
int K;
string S;
int N;
vector<vector<int>> dp;

int mm = 1000000007;

void getInput() {
  cin >> K;
  cin >> S;
  N = K + S.size();
  dp = vector<vector<int>>(N + 1, vector<int>(S.size() + 1, 0));
}

void solve() {
  dp[0][0] = 1;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < S.size() + 1; ++j) {
      if (j == S.size()) {
        dp[i + 1][j] += dp[i][j] * 26;

        dp[i + 1][j] = dp[i + 1][j] % mm;
      } else {
        dp[i + 1][j] += dp[i][j] * 25;
        dp[i + 1][j + 1] += dp[i][j];

        dp[i + 1][j] = dp[i + 1][j] % mm;
        dp[i + 1][j + 1] = dp[i + 1][j + 1] % mm;
      }
    }
  }
  cout << dp[N][S.size()] << endl;
}

signed main() {

  getInput();
  solve();

  return 0;
}