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

// #include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1},
          Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)                                                               \\
  cout << #v << ":";                                                           \\
  for (auto x : v) {                                                           \\
    cout << x << ' ';                                                          \\
  }                                                                            \\
  cout << endl;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
// cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll M = pow(10, 9) + 7;

vector<ll> fac(2000001);  // n!(mod M)
vector<ll> ifac(2000001); // k!^{M-2} (mod M)
ll mpow(ll x, ll n) {     // x^n(mod M)
  ll ans = 1;
  while (n != 0) {
    if (n & 1)
      ans = ans * x % M;
    x = x * x % M;
    n = n >> 1;
  }
  return ans;
}
// conbination
ll comb(ll a, ll b) { // aCb(mod M)
  if (a == 0 && b == 0)
    return 1;
  if (a < b || a < 0)
    return 0;
  ll tmp = ifac[a - b] * ifac[b] % M;
  return tmp * fac[a] % M;
}
// 素因数分解o√n
map<int, int> prime_factor(int n) {
  map<int, int> res;
  for (int i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ++res[i];
      n /= i;
    }
  }
  if (n != 1)
    res[n] = 1;
  // for (int i = 2; i <= n; i++)
  // cout << res[i] << "\\n";
  return res;
}
// n!
ll fact_mod(ll n) {
  ll ret = 1;
  for (ll i = 2; i <= n; i++)
    ret = ret * (i % MOD) % MOD;
  return ret;
}

// 繰り返し二乗法
ll pow_mod(ll x, ll n) {
  if (n == 0)
    return 1;
  ll ret = pow_mod((x * x) % MOD, n / 2);
  if (n & 1)
    ret = (ret * x) % MOD;
  return ret;
}

// nCr O(r) nがでかくても安心
ll combination_mod(ll n, ll r) {
  if (r > n - r)
    r = n - r;
  if (r == 0)
    return 1;
  ll a = 1;
  // a=n!/(n-r)!=n~n-r+1までの総積->O(r)
  for (ll i = 0; i < r; i++)
    a = a * ((n - i) % MOD) % MOD;
  // b=inv(r!)
  ll b = pow_mod(fact_mod(r), MOD - 2);
  return (a % MOD) * (b % MOD) % MOD;
}

ll inv_mod(ll n) {
  // フェルマーの小定理
  return pow_mod(n, MOD - 2);
}
const int N_MAX = 1001;
double pascal[N_MAX][N_MAX] = {};

// パスカルの三角形
// 確率Ver
// n段目は 2^n で割った値が入る (横の和 = 1)

void calc_pascal() {
  FOR(i, 0, N_MAX) { pascal[i][0] = 1.0 / pow(2.0f, i); }
  pascal[1][1] = 1.0 / 2.0;

  FOR(i, 2, N_MAX) {
    for (int j = 1; j <= i; j++) {
      pascal[i][j] = pascal[i - 1][j] + pascal[i - 1][j - 1];
      pascal[i][j] /= 2.0;
    }
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  fac[0] = 1;
  ifac[0] = 1;
  for (ll i = 0; i < 2000000; i++) {
    fac[i + 1] = fac[i] * (i + 1) % M;              // n!(mod M)
    ifac[i + 1] = ifac[i] * mpow(i + 1, M - 2) % M; // k!^{M-2} (mod M)
  }
  ll k;
  string s;
  cin >> k >> s;
  ll sksize = k + ll(s.size());
  ll ans = 0;
  for (ll i = 0; i <= k; i++) {
    ll temp = pow_mod(26, i) * pow_mod(25, k - i);
    temp %= MOD;
    temp *= comb(ll(s.size()) + k - i - 1, ll(s.size()) - 1);
    temp %= MOD;
    ans += temp;
    ans %= MOD;
  }
  cout << ans << "\\n";
}


Error: 0

Fixed submission:

// #include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1},
          Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)                                                               \\
  cout << #v << ":";                                                           \\
  for (auto x : v) {                                                           \\
    cout << x << ' ';                                                          \\
  }                                                                            \\
  cout << endl;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
// cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll M = pow(10, 9) + 7;

vector<ll> fac(1000001);  // n!(mod M)
vector<ll> ifac(1000001); // k!^{M-2} (mod M)
ll mpow(ll x, ll n) {     // x^n(mod M)
  ll ans = 1;
  while (n != 0) {
    if (n & 1)
      ans = ans * x % M;
    x = x * x % M;
    n = n >> 1;
  }
  return ans;
}
// conbination
ll comb(ll a, ll b) { // aCb(mod M)
  if (a == 0 && b == 0)
    return 1;
  if (a < b || a < 0)
    return 0;
  ll tmp = ifac[a - b] * ifac[b] % M;
  return tmp * fac[a] % M;
}
// 素因数分解o√n
map<int, int> prime_factor(int n) {
  map<int, int> res;
  for (int i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ++res[i];
      n /= i;
    }
  }
  if (n != 1)
    res[n] = 1;
  // for (int i = 2; i <= n; i++)
  // cout << res[i] << "\\n";
  return res;
}
// n!
ll fact_mod(ll n) {
  ll ret = 1;
  for (ll i = 2; i <= n; i++)
    ret = ret * (i % MOD) % MOD;
  return ret;
}

// 繰り返し二乗法
ll pow_mod(ll x, ll n) {
  if (n == 0)
    return 1;
  ll ret = pow_mod((x * x) % MOD, n / 2);
  if (n & 1)
    ret = (ret * x) % MOD;
  return ret;
}

// nCr O(r) nがでかくても安心
ll combination_mod(ll n, ll r) {
  if (r > n - r)
    r = n - r;
  if (r == 0)
    return 1;
  ll a = 1;
  // a=n!/(n-r)!=n~n-r+1までの総積->O(r)
  for (ll i = 0; i < r; i++)
    a = a * ((n - i) % MOD) % MOD;
  // b=inv(r!)
  ll b = pow_mod(fact_mod(r), MOD - 2);
  return (a % MOD) * (b % MOD) % MOD;
}

ll inv_mod(ll n) {
  // フェルマーの小定理
  return pow_mod(n, MOD - 2);
}
const int N_MAX = 1001;
double pascal[N_MAX][N_MAX] = {};

// パスカルの三角形
// 確率Ver
// n段目は 2^n で割った値が入る (横の和 = 1)

void calc_pascal() {
  FOR(i, 0, N_MAX) { pascal[i][0] = 1.0 / pow(2.0f, i); }
  pascal[1][1] = 1.0 / 2.0;

  FOR(i, 2, N_MAX) {
    for (int j = 1; j <= i; j++) {
      pascal[i][j] = pascal[i - 1][j] + pascal[i - 1][j - 1];
      pascal[i][j] /= 2.0;
    }
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  fac[0] = 1;
  ifac[0] = 1;
  for (ll i = 0; i < 1000000; i++) {
    fac[i + 1] = fac[i] * (i + 1) % M;              // n!(mod M)
    ifac[i + 1] = ifac[i] * mpow(i + 1, M - 2) % M; // k!^{M-2} (mod M)
  }
  ll k;
  string s;
  cin >> k >> s;
  ll sksize = k + ll(s.size());
  ll ans = 0;
  for (ll i = 0; i <= k; i++) {
    ll temp = pow_mod(26, i) * pow_mod(25, k - i);
    temp %= MOD;
    temp *= comb(ll(s.size()) + k - i - 1, ll(s.size()) - 1);
    temp %= MOD;
    ans += temp;
    ans %= MOD;
  }
  cout << ans << "\\n";
}