Submission #14566066


Source Code Expand

Copy
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

// #define mod (ll)(1e9 + 7)

template <ll ModVal>
struct ModInt {
  ll x;

  ModInt(ll _x = 0) : x((_x % ModVal + ModVal) % ModVal) {
  }

  ModInt operator-() const {
    return ModInt(-x);
  }
  ModInt& operator+=(const ModInt a) {
    x += a.x;
    if (x >= ModVal)
      x -= ModVal;
    return *this;
  }
  ModInt& operator-=(const ModInt a) {
    x = x + ModVal - a.x;
    if (x >= ModVal)
      x -= ModVal;
    return *this;
  }
  ModInt& operator*=(const ModInt a) {
    x *= a.x;
    x %= ModVal;
    return *this;
  }

  ll ext_gcd(ll a, ll b, ll& x, ll& y) {
    if (b == 0) {
      x = 1;
      y = 0;
      return a;
    }
    ll tmp = a / b;
    ll d = ext_gcd(b, a - b * tmp, y, x);
    y -= tmp * x;
    return d;
  }

  // 逆元
  ModInt inv() {
    ll u, v;
    ext_gcd(x, ModVal, u, v);
    return ModInt(u);
  }

  ModInt inv(const ModInt a) {
    ll u, v;
    ext_gcd(a.x, ModVal, u, v);
    return ModInt(u);
  }

  ModInt& operator/=(const ModInt a) {
    return (*this) *= inv(a);
  }

  ModInt operator+(const ModInt a) const {
    ModInt retval(*this);
    return retval += a;
  }
  ModInt operator-(const ModInt a) const {
    ModInt retval(*this);
    return retval -= a;
  }
  ModInt operator*(const ModInt a) const {
    ModInt retval(*this);
    return retval *= a;
  }
  ModInt operator/(const ModInt a) const {
    ModInt retval(*this);
    return retval /= a;
  }

  ModInt pow(ll n) {
    ModInt ans(1);
    while (n) {
      if (n & 1)
        ans = ans * x;
      *this = (*this) * (*this);
      n = n >> 1;
    }
    return ans;
  }

  constexpr const ll& value() {
    return this->x;
  }
};

template <ll ModVal>
ostream& operator<<(ostream& os, const ModInt<ModVal>& a) {
  os << a.x;
  return os;
}

using mint = ModInt<mod>;

template <typename T>
class Combination {
 public:
  Combination(ll _max_n) : max_n(_max_n), factional(max_n + 1), inv(max_n + 1) {
    factional[0] = 1;
    inv[0] = 1;
    for (ll i = 0; i < max_n; i++) {
      factional[i + 1] = factional[i] * (i + 1); // n!(mod M)
      inv[i + 1] = inv[i] / (i + 1);             // k!^(M-2) (mod M)
    }
  }

  // nCk
  T choose(ll n, ll k) {
    if (n == 0 && k == 0)
      return 1;
    if (n < k || n < 0)
      return 0;
    T tmp = inv[n - k] * inv[k];
    return tmp * factional[n];
  }

  T permutation(ll n, ll k) {
    if (n - k < 0) {
      return 0;
    }
    return factional[n] / factional[n - k];
  }

 private:
  const ll max_n;
  std::vector<T> factional;
  std::vector<T> inv;
};

using Comb = Combination<mint>;

using vm = vector<mint>;
using vvm = vector<vm>;
using vvvm = vector<vvm>;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll k;
  cin >> k;
  string s;
  cin >> s;

  // 最終的な文字列の長さ
  ll n = s.size() + k;
#if 0
  vvll dp(n + 1, vll(n + 1));
  dp[0][0] = 1;
  rep(i, n) {
    rep(j, n) {
      dp[i + 1][j] += dp[i][j] * 25;
      dp[i + 1][j + 1] += dp[i][j];
    }
  }

  ll ans = 0;
  FOR(i, n - k, n + 1) {
    ans += dp[n][i];
  }

  cout << ans << endl;
#endif

  vm pow25(n + 10);
  pow25[0] = 1;
  rep(i, n + 1) {
    pow25[i + 1] = pow25[i] * 25;
  }

  Comb C(n + 10);

  mint ans = 0;
  FOR(i, n - k, n + 1) {
    mint ptn = 0;
    ptn = C.choose(n, i) * pow25[n - i];
    ans += ptn;
  }

  cout << ans << endl;

  return 0;
}

Submission Info

Submission Time
Task F - Strivore
User spiralray
Language C++ (GCC 9.2.1)
Score 600
Code Size 4212 Byte
Status
Exec Time 455 ms
Memory 51228 KB

Judge Result

Set Name Sample Subtask1
Score / Max Score 0 / 0 600 / 600
Status
× 2
× 30
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
Subtask1 sample_01.txt, sample_02.txt, sub1_01.txt, sub1_02.txt, sub1_03.txt, sub1_04.txt, sub1_05.txt, sub1_06.txt, sub1_07.txt, sub1_08.txt, sub1_09.txt, sub1_10.txt, sub1_11.txt, sub1_12.txt, sub1_13.txt, sub1_14.txt, sub1_15.txt, sub1_16.txt, sub1_17.txt, sub1_18.txt, sub1_19.txt, sub1_20.txt, sub1_21.txt, sub1_22.txt, sub1_23.txt, sub1_24.txt, sub1_25.txt, sub1_26.txt, sub1_27.txt, sub1_28.txt
Case Name Status Exec Time Memory
sample_01.txt 7 ms 3504 KB
sample_02.txt 10 ms 3912 KB
sub1_01.txt 444 ms 51180 KB
sub1_02.txt 447 ms 51228 KB
sub1_03.txt 445 ms 51148 KB
sub1_04.txt 455 ms 51144 KB
sub1_05.txt 40 ms 7280 KB
sub1_06.txt 151 ms 20280 KB
sub1_07.txt 176 ms 22928 KB
sub1_08.txt 219 ms 27644 KB
sub1_09.txt 216 ms 27680 KB
sub1_10.txt 220 ms 27576 KB
sub1_11.txt 147 ms 18140 KB
sub1_12.txt 91 ms 12072 KB
sub1_13.txt 229 ms 26596 KB
sub1_14.txt 76 ms 10828 KB
sub1_15.txt 25 ms 4944 KB
sub1_16.txt 17 ms 3888 KB
sub1_17.txt 3 ms 3512 KB
sub1_18.txt 2 ms 3508 KB
sub1_19.txt 2 ms 3444 KB
sub1_20.txt 267 ms 31624 KB
sub1_21.txt 200 ms 24684 KB
sub1_22.txt 296 ms 35236 KB
sub1_23.txt 157 ms 20004 KB
sub1_24.txt 322 ms 37092 KB
sub1_25.txt 223 ms 27056 KB
sub1_26.txt 131 ms 17380 KB
sub1_27.txt 268 ms 31868 KB
sub1_28.txt 90 ms 12072 KB