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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i, m, n) for (ll i = (m); i <= (n); i++)
#define zep(i, m, n) for (ll i = (m); i < (n); i++)
#define rrep(i, m, n) for (ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x, m, n)                                                        \\
  for (int i = (m); i <= n; i++) {                                             \\
    cout << (x[i]) << " ";                                                     \\
  }                                                                            \\
  cout << endl;

const long long MAX = 2e6 + 100;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long powmod(long long a, long long x) {
  if (x == 0)
    return 1;
  long long r = powmod(a, x / 2);
  return (x % 2) ? (r * r % MOD) * a % MOD : r * r % MOD;
}

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

  COMinit();
  ll k;
  cin >> k;
  string s;
  cin >> s;
  ll n = s.size();

  ll ans = 0;
  rep(i, 0, k) {
    ans += COM(n - 1 + k - i, k - i) * powmod(25, k - i) % MOD * powmod(26, i) %
           MOD;
    ans %= MOD;
  }
  print(ans)

      return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i, m, n) for (ll i = (m); i <= (n); i++)
#define zep(i, m, n) for (ll i = (m); i < (n); i++)
#define rrep(i, m, n) for (ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x, m, n)                                                        \\
  for (int i = (m); i <= n; i++) {                                             \\
    cout << (x[i]) << " ";                                                     \\
  }                                                                            \\
  cout << endl;

const long long MAX = 1e6 + 100;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long powmod(long long a, long long x) {
  if (x == 0)
    return 1;
  long long r = powmod(a, x / 2);
  return (x % 2) ? (r * r % MOD) * a % MOD : r * r % MOD;
}

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

  COMinit();
  ll k;
  cin >> k;
  string s;
  cin >> s;
  ll n = s.size();

  ll ans = 0;
  rep(i, 0, k) {
    ans += COM(n - 1 + k - i, k - i) * powmod(25, k - i) % MOD * powmod(26, i) %
           MOD;
    ans %= MOD;
  }
  print(ans)

      return 0;
}