QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#120007#5739. Super Meat Broshos_lyricAC ✓2091ms28768kbC++1418.3kb2023-07-06 10:55:422023-07-06 10:55:44

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-06 10:55:44]
  • 评测
  • 测评结果:AC
  • 用时:2091ms
  • 内存:28768kb
  • [2023-07-06 10:55:42]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }

////////////////////////////////////////////////////////////////////////////////
template <unsigned M_> struct ModInt {
  static constexpr unsigned M = M_;
  unsigned x;
  constexpr ModInt() : x(0U) {}
  constexpr ModInt(unsigned x_) : x(x_ % M) {}
  constexpr ModInt(unsigned long long x_) : x(x_ % M) {}
  constexpr ModInt(int x_) : x(((x_ %= static_cast<int>(M)) < 0) ? (x_ + static_cast<int>(M)) : x_) {}
  constexpr ModInt(long long x_) : x(((x_ %= static_cast<long long>(M)) < 0) ? (x_ + static_cast<long long>(M)) : x_) {}
  ModInt &operator+=(const ModInt &a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; }
  ModInt &operator-=(const ModInt &a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; }
  ModInt &operator*=(const ModInt &a) { x = (static_cast<unsigned long long>(x) * a.x) % M; return *this; }
  ModInt &operator/=(const ModInt &a) { return (*this *= a.inv()); }
  ModInt pow(long long e) const {
    if (e < 0) return inv().pow(-e);
    ModInt a = *this, b = 1U; for (; e; e >>= 1) { if (e & 1) b *= a; a *= a; } return b;
  }
  ModInt inv() const {
    unsigned a = M, b = x; int y = 0, z = 1;
    for (; b; ) { const unsigned q = a / b; const unsigned c = a - q * b; a = b; b = c; const int w = y - static_cast<int>(q) * z; y = z; z = w; }
    assert(a == 1U); return ModInt(y);
  }
  ModInt operator+() const { return *this; }
  ModInt operator-() const { ModInt a; a.x = x ? (M - x) : 0U; return a; }
  ModInt operator+(const ModInt &a) const { return (ModInt(*this) += a); }
  ModInt operator-(const ModInt &a) const { return (ModInt(*this) -= a); }
  ModInt operator*(const ModInt &a) const { return (ModInt(*this) *= a); }
  ModInt operator/(const ModInt &a) const { return (ModInt(*this) /= a); }
  template <class T> friend ModInt operator+(T a, const ModInt &b) { return (ModInt(a) += b); }
  template <class T> friend ModInt operator-(T a, const ModInt &b) { return (ModInt(a) -= b); }
  template <class T> friend ModInt operator*(T a, const ModInt &b) { return (ModInt(a) *= b); }
  template <class T> friend ModInt operator/(T a, const ModInt &b) { return (ModInt(a) /= b); }
  explicit operator bool() const { return x; }
  bool operator==(const ModInt &a) const { return (x == a.x); }
  bool operator!=(const ModInt &a) const { return (x != a.x); }
  friend std::ostream &operator<<(std::ostream &os, const ModInt &a) { return os << a.x; }
};
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
// M: prime, G: primitive root, 2^K | M - 1
template <unsigned M_, unsigned G_, int K_> struct Fft {
  static_assert(2U <= M_, "Fft: 2 <= M must hold.");
  static_assert(M_ < 1U << 30, "Fft: M < 2^30 must hold.");
  static_assert(1 <= K_, "Fft: 1 <= K must hold.");
  static_assert(K_ < 30, "Fft: K < 30 must hold.");
  static_assert(!((M_ - 1U) & ((1U << K_) - 1U)), "Fft: 2^K | M - 1 must hold.");
  static constexpr unsigned M = M_;
  static constexpr unsigned M2 = 2U * M_;
  static constexpr unsigned G = G_;
  static constexpr int K = K_;
  ModInt<M> FFT_ROOTS[K + 1], INV_FFT_ROOTS[K + 1];
  ModInt<M> FFT_RATIOS[K], INV_FFT_RATIOS[K];
  Fft() {
    const ModInt<M> g(G);
    for (int k = 0; k <= K; ++k) {
      FFT_ROOTS[k] = g.pow((M - 1U) >> k);
      INV_FFT_ROOTS[k] = FFT_ROOTS[k].inv();
    }
    for (int k = 0; k <= K - 2; ++k) {
      FFT_RATIOS[k] = -g.pow(3U * ((M - 1U) >> (k + 2)));
      INV_FFT_RATIOS[k] = FFT_RATIOS[k].inv();
    }
    assert(FFT_ROOTS[1] == M - 1U);
  }
  // as[rev(i)] <- \sum_j \zeta^(ij) as[j]
  void fft(ModInt<M> *as, int n) const {
    assert(!(n & (n - 1))); assert(1 <= n); assert(n <= 1 << K);
    int m = n;
    if (m >>= 1) {
      for (int i = 0; i < m; ++i) {
        const unsigned x = as[i + m].x;  // < M
        as[i + m].x = as[i].x + M - x;  // < 2 M
        as[i].x += x;  // < 2 M
      }
    }
    if (m >>= 1) {
      ModInt<M> prod = 1U;
      for (int h = 0, i0 = 0; i0 < n; i0 += (m << 1)) {
        for (int i = i0; i < i0 + m; ++i) {
          const unsigned x = (prod * as[i + m]).x;  // < M
          as[i + m].x = as[i].x + M - x;  // < 3 M
          as[i].x += x;  // < 3 M
        }
        prod *= FFT_RATIOS[__builtin_ctz(++h)];
      }
    }
    for (; m; ) {
      if (m >>= 1) {
        ModInt<M> prod = 1U;
        for (int h = 0, i0 = 0; i0 < n; i0 += (m << 1)) {
          for (int i = i0; i < i0 + m; ++i) {
            const unsigned x = (prod * as[i + m]).x;  // < M
            as[i + m].x = as[i].x + M - x;  // < 4 M
            as[i].x += x;  // < 4 M
          }
          prod *= FFT_RATIOS[__builtin_ctz(++h)];
        }
      }
      if (m >>= 1) {
        ModInt<M> prod = 1U;
        for (int h = 0, i0 = 0; i0 < n; i0 += (m << 1)) {
          for (int i = i0; i < i0 + m; ++i) {
            const unsigned x = (prod * as[i + m]).x;  // < M
            as[i].x = (as[i].x >= M2) ? (as[i].x - M2) : as[i].x;  // < 2 M
            as[i + m].x = as[i].x + M - x;  // < 3 M
            as[i].x += x;  // < 3 M
          }
          prod *= FFT_RATIOS[__builtin_ctz(++h)];
        }
      }
    }
    for (int i = 0; i < n; ++i) {
      as[i].x = (as[i].x >= M2) ? (as[i].x - M2) : as[i].x;  // < 2 M
      as[i].x = (as[i].x >= M) ? (as[i].x - M) : as[i].x;  // < M
    }
  }
  // as[i] <- (1/n) \sum_j \zeta^(-ij) as[rev(j)]
  void invFft(ModInt<M> *as, int n) const {
    assert(!(n & (n - 1))); assert(1 <= n); assert(n <= 1 << K);
    int m = 1;
    if (m < n >> 1) {
      ModInt<M> prod = 1U;
      for (int h = 0, i0 = 0; i0 < n; i0 += (m << 1)) {
        for (int i = i0; i < i0 + m; ++i) {
          const unsigned long long y = as[i].x + M - as[i + m].x;  // < 2 M
          as[i].x += as[i + m].x;  // < 2 M
          as[i + m].x = (prod.x * y) % M;  // < M
        }
        prod *= INV_FFT_RATIOS[__builtin_ctz(++h)];
      }
      m <<= 1;
    }
    for (; m < n >> 1; m <<= 1) {
      ModInt<M> prod = 1U;
      for (int h = 0, i0 = 0; i0 < n; i0 += (m << 1)) {
        for (int i = i0; i < i0 + (m >> 1); ++i) {
          const unsigned long long y = as[i].x + M2 - as[i + m].x;  // < 4 M
          as[i].x += as[i + m].x;  // < 4 M
          as[i].x = (as[i].x >= M2) ? (as[i].x - M2) : as[i].x;  // < 2 M
          as[i + m].x = (prod.x * y) % M;  // < M
        }
        for (int i = i0 + (m >> 1); i < i0 + m; ++i) {
          const unsigned long long y = as[i].x + M - as[i + m].x;  // < 2 M
          as[i].x += as[i + m].x;  // < 2 M
          as[i + m].x = (prod.x * y) % M;  // < M
        }
        prod *= INV_FFT_RATIOS[__builtin_ctz(++h)];
      }
    }
    if (m < n) {
      for (int i = 0; i < m; ++i) {
        const unsigned y = as[i].x + M2 - as[i + m].x;  // < 4 M
        as[i].x += as[i + m].x;  // < 4 M
        as[i + m].x = y;  // < 4 M
      }
    }
    const ModInt<M> invN = ModInt<M>(n).inv();
    for (int i = 0; i < n; ++i) {
      as[i] *= invN;
    }
  }
  void fft(vector<ModInt<M>> &as) const {
    fft(as.data(), as.size());
  }
  void invFft(vector<ModInt<M>> &as) const {
    invFft(as.data(), as.size());
  }
  vector<ModInt<M>> convolve(vector<ModInt<M>> as, vector<ModInt<M>> bs) const {
    if (as.empty() || bs.empty()) return {};
    const int len = as.size() + bs.size() - 1;
    int n = 1;
    for (; n < len; n <<= 1) {}
    as.resize(n); fft(as);
    bs.resize(n); fft(bs);
    for (int i = 0; i < n; ++i) as[i] *= bs[i];
    invFft(as);
    as.resize(len);
    return as;
  }
  vector<ModInt<M>> square(vector<ModInt<M>> as) const {
    if (as.empty()) return {};
    const int len = as.size() + as.size() - 1;
    int n = 1;
    for (; n < len; n <<= 1) {}
    as.resize(n); fft(as);
    for (int i = 0; i < n; ++i) as[i] *= as[i];
    invFft(as);
    as.resize(len);
    return as;
  }
};

// M0 M1 M2 = 789204840662082423367925761 (> 7.892 * 10^26, > 2^89)
// M0 M3 M4 M5 M6 = 797766583174034668024539679147517452591562753 (> 7.977 * 10^44, > 2^149)
const Fft<998244353U, 3U, 23> FFT0;
const Fft<897581057U, 3U, 23> FFT1;
const Fft<880803841U, 26U, 23> FFT2;
const Fft<985661441U, 3U, 22> FFT3;
const Fft<943718401U, 7U, 22> FFT4;
const Fft<935329793U, 3U, 22> FFT5;
const Fft<918552577U, 5U, 22> FFT6;

// T = unsigned, unsigned long long, ModInt<M>
template <class T, unsigned M0, unsigned M1, unsigned M2>
T garner(ModInt<M0> a0, ModInt<M1> a1, ModInt<M2> a2) {
  static const ModInt<M1> INV_M0_M1 = ModInt<M1>(M0).inv();
  static const ModInt<M2> INV_M0M1_M2 = (ModInt<M2>(M0) * M1).inv();
  const ModInt<M1> b1 = INV_M0_M1 * (a1 - a0.x);
  const ModInt<M2> b2 = INV_M0M1_M2 * (a2 - (ModInt<M2>(b1.x) * M0 + a0.x));
  return (T(b2.x) * M1 + b1.x) * M0 + a0.x;
}
template <class T, unsigned M0, unsigned M1, unsigned M2, unsigned M3, unsigned M4>
T garner(ModInt<M0> a0, ModInt<M1> a1, ModInt<M2> a2, ModInt<M3> a3, ModInt<M4> a4) {
  static const ModInt<M1> INV_M0_M1 = ModInt<M1>(M0).inv();
  static const ModInt<M2> INV_M0M1_M2 = (ModInt<M2>(M0) * M1).inv();
  static const ModInt<M3> INV_M0M1M2_M3 = (ModInt<M3>(M0) * M1 * M2).inv();
  static const ModInt<M4> INV_M0M1M2M3_M4 = (ModInt<M4>(M0) * M1 * M2 * M3).inv();
  const ModInt<M1> b1 = INV_M0_M1 * (a1 - a0.x);
  const ModInt<M2> b2 = INV_M0M1_M2 * (a2 - (ModInt<M2>(b1.x) * M0 + a0.x));
  const ModInt<M3> b3 = INV_M0M1M2_M3 * (a3 - ((ModInt<M3>(b2.x) * M1 + b1.x) * M0 + a0.x));
  const ModInt<M4> b4 = INV_M0M1M2M3_M4 * (a4 - (((ModInt<M4>(b3.x) * M2 + b2.x) * M1 + b1.x) * M0 + a0.x));
  return (((T(b4.x) * M3 + b3.x) * M2 + b2.x) * M1 + b1.x) * M0 + a0.x;
}

template <unsigned M> vector<ModInt<M>> convolve(const vector<ModInt<M>> &as, const vector<ModInt<M>> &bs) {
  static constexpr unsigned M0 = decltype(FFT0)::M;
  static constexpr unsigned M1 = decltype(FFT1)::M;
  static constexpr unsigned M2 = decltype(FFT2)::M;
  if (as.empty() || bs.empty()) return {};
  const int asLen = as.size(), bsLen = bs.size();
  vector<ModInt<M0>> as0(asLen), bs0(bsLen);
  for (int i = 0; i < asLen; ++i) as0[i] = as[i].x;
  for (int i = 0; i < bsLen; ++i) bs0[i] = bs[i].x;
  const vector<ModInt<M0>> cs0 = FFT0.convolve(as0, bs0);
  vector<ModInt<M1>> as1(asLen), bs1(bsLen);
  for (int i = 0; i < asLen; ++i) as1[i] = as[i].x;
  for (int i = 0; i < bsLen; ++i) bs1[i] = bs[i].x;
  const vector<ModInt<M1>> cs1 = FFT1.convolve(as1, bs1);
  vector<ModInt<M2>> as2(asLen), bs2(bsLen);
  for (int i = 0; i < asLen; ++i) as2[i] = as[i].x;
  for (int i = 0; i < bsLen; ++i) bs2[i] = bs[i].x;
  const vector<ModInt<M2>> cs2 = FFT2.convolve(as2, bs2);
  vector<ModInt<M>> cs(asLen + bsLen - 1);
  for (int i = 0; i < asLen + bsLen - 1; ++i) {
    cs[i] = garner<ModInt<M>>(cs0[i], cs1[i], cs2[i]);
  }
  return cs;
}
template <unsigned M> vector<ModInt<M>> square(const vector<ModInt<M>> &as) {
  static constexpr unsigned M0 = decltype(FFT0)::M;
  static constexpr unsigned M1 = decltype(FFT1)::M;
  static constexpr unsigned M2 = decltype(FFT2)::M;
  if (as.empty()) return {};
  const int asLen = as.size();
  vector<ModInt<M0>> as0(asLen);
  for (int i = 0; i < asLen; ++i) as0[i] = as[i].x;
  const vector<ModInt<M0>> cs0 = FFT0.square(as0);
  vector<ModInt<M1>> as1(asLen);
  for (int i = 0; i < asLen; ++i) as1[i] = as[i].x;
  const vector<ModInt<M1>> cs1 = FFT1.square(as1);
  vector<ModInt<M2>> as2(asLen);
  for (int i = 0; i < asLen; ++i) as2[i] = as[i].x;
  const vector<ModInt<M2>> cs2 = FFT2.square(as2);
  vector<ModInt<M>> cs(asLen + asLen - 1);
  for (int i = 0; i < asLen + asLen - 1; ++i) {
    cs[i] = garner<ModInt<M>>(cs0[i], cs1[i], cs2[i]);
  }
  return cs;
}


constexpr unsigned MO = 1'000'000'009;
using Mint = ModInt<MO>;

constexpr int LIM_INV = 1'000'010;
Mint inv[LIM_INV], fac[LIM_INV], invFac[LIM_INV];

void prepare() {
  inv[1] = 1;
  for (int i = 2; i < LIM_INV; ++i) {
    inv[i] = -((Mint::M / i) * inv[Mint::M % i]);
  }
  fac[0] = invFac[0] = 1;
  for (int i = 1; i < LIM_INV; ++i) {
    fac[i] = fac[i - 1] * i;
    invFac[i] = invFac[i - 1] * inv[i];
  }
}
Mint binom(Int n, Int k) {
  if (n < 0) {
    if (k >= 0) {
      return ((k & 1) ? -1 : +1) * binom(-n + k - 1, k);
    } else if (n - k >= 0) {
      return (((n - k) & 1) ? -1 : +1) * binom(-k - 1, n - k);
    } else {
      return 0;
    }
  } else {
    if (0 <= k && k <= n) {
      assert(n < LIM_INV);
      return fac[n] * invFac[k] * invFac[n - k];
    } else {
      return 0;
    }
  }
}


vector<Mint> polyInv(const vector<Mint> &as, int n) {
  assert(!as.empty()); assert(as[0].x != 0);
  const int asLen = as.size();
  vector<Mint> bs{as[0].inv()};
  for (int m = 1; m < n; m <<= 1) {
    const vector<Mint> as0(as.begin(), as.begin() + min(m << 1, asLen));
    const auto cs = convolve(as0, square(bs));
    bs.resize(m << 1, 0);
    for (int i = m; i < m << 1 && i < (int)cs.size(); ++i) bs[i] -= cs[i];
  }
  return bs;
}

// O(|as| + n (log n)^2)
vector<Mint> polyExp(vector<Mint> as, int n) {
  assert(!as.empty()); assert(!as[0]);
  const int asLen = as.size();
  for (int i = 0; i < asLen; ++i) as[i] *= i;
  vector<Mint> bs(n, 0);
  bs[0] = 1;
  for (int i = 1; i < n; ++i) {
    const int w = i & -i;
    const vector<Mint> as0(as.begin(), as.begin() + min(w << 1, asLen));
    const vector<Mint> bs0(bs.begin() + (i - w), bs.begin() + i);
    const auto prod = convolve(as0, bs0);
    for (int j = i; j < i + w && j < n && j - (i - w) < (int)prod.size(); ++j) bs[j] += prod[j - (i - w)];
    bs[i] *= inv[i];
  }
  return bs;
}

// [x^n] a/b
Mint polyDivAt(vector<Mint> as, vector<Mint> bs, long long n) {
  const int len = max(as.size(), bs.size());
  as.resize(len, 0);
  bs.resize(len, 0);
  assert(len > 0); assert(bs[0]);
  for (; n >= len; n >>= 1) {
    auto cs = bs;
    for (int i = 1; i < len; i += 2) cs[i] = -cs[i];
    as = convolve(as, cs);
    bs = convolve(bs, cs);
    as.resize(len << 1);
    for (int i = 0; i < len; ++i) as[i] = as[2 * i + (n & 1)];
    for (int i = 0; i < len; ++i) bs[i] = bs[2 * i];
    as.resize(len);
    bs.resize(len);
  }
  bs = polyInv(bs, n + 1);
  Mint ret = 0;
  for (int i = 0; i <= n; ++i) ret += as[i] * bs[n - i];
  return ret;
}

Mint linearRecurrenceAt(const vector<Mint> &as, const vector<Mint> &cs, long long k) {
  assert(!cs.empty()); assert(cs[0]);
  const int d = (int)cs.size() - 1;
  assert((int)as.size() >= d);
  const vector<Mint> as0(as.begin(), as.begin() + d);
  auto bs = convolve(as0, cs);
  bs.resize(d);
  return polyDivAt(bs, cs, k);
}

/*
  Given  : \sum[0<=i<=m] as[i] X^i = \prod[j] (1 - alpha[j] X)
  Returns: bs[k] := \sum[j] alpha^k  (0 <= k < n)
  
  b = m - (X (d/dX) a) / a
*/
vector<Mint> polyToPowerSums(const vector<Mint> &as, int n) {
  assert(!as.empty()); assert(as[0].x == 1);
  const int m = (int)as.size() - 1;
  auto bs = as;
  for (int i = 0; i <= m; ++i) bs[i] *= i;
  bs = convolve(bs, polyInv(as, n));
  bs.resize(n);
  for (int i = 0; i < n; ++i) bs[i] = -bs[i];
  bs[0] = m;
  return bs;
}

/*
  Given  : bs[k] := \sum[j] alpha^k  (0 <= k < n)
  Returns: \sum[0<=i<=m] as[i] X^i = \prod[j] (1 - alpha[j] X)
  
  a = exp(\int dx (1/x) (m - b))
*/
vector<Mint> powerSumsToPoly(vector<Mint> bs) {
  assert(!bs.empty());
  const int m = (int)bs.size() - 1;
  assert(bs[0] == Mint(m));
  bs[0] = 0;
  for (int i = 1; i <= m; ++i) bs[i] *= -inv[i];
  return polyExp(bs, m + 1);
}

/*
  Given  : \sum[0<=i<=m] as[i] X^i = \prod[j] (1 - alpha[j] X)
           \sum[0<=i<=n] bs[i] X^i = \prod[j] (1 - beta[j] X)
  Returns: \sum[0<=i<=mn] cs[i] X^i = \prod[j,k] (1 - (alpha[j] + beta[k]) X)
*/
vector<Mint> addPolyRoots(const vector<Mint> &as, const vector<Mint> &bs) {
  assert(!as.empty()); assert(as[0].x == 1);
  assert(!bs.empty()); assert(bs[0].x == 1);
  const int m = (int)as.size() - 1;
  const int n = (int)bs.size() - 1;
  auto cs = polyToPowerSums(as, m * n + 1);
  auto ds = polyToPowerSums(bs, m * n + 1);
  for (int i = 0; i <= m * n; ++i) cs[i] *= invFac[i];
  for (int i = 0; i <= m * n; ++i) ds[i] *= invFac[i];
  auto es = convolve(cs, ds);
  es.resize(m * n + 1);
  for (int i = 0; i <= m * n; ++i) es[i] *= fac[i];
  return powerSumsToPoly(es);
}


int N;
Int M;
vector<Mint> A, B;

int main() {
  prepare();
  
  for (; ~scanf("%d%lld", &N, &M); ) {
    A.resize(N + 1); for (int i = 1; i <= N; ++i) scanf("%u", &A[i].x);
    B.resize(N + 1); for (int i = 1; i <= N; ++i) scanf("%u", &B[i].x);
    
    for (int i = 1; i <= N; ++i) A[i] = -A[i];
    for (int i = 1; i <= N; ++i) B[i] = -B[i];
    A[0] = 1;
    B[0] = 1;
    
    const auto cs = addPolyRoots(A, B);
// cerr<<"cs = "<<cs<<endl;
    
    const int len = N*N + 10;
    auto fs = polyInv(A, len);
    auto gs = polyInv(B, len);
    for (int i = 0; i < len; ++i) fs[i] *= invFac[i];
    for (int i = 0; i < len; ++i) gs[i] *= invFac[i];
    auto hs = convolve(fs, gs);
    hs.resize(len);
    for (int i = 0; i < len; ++i) hs[i] *= fac[i];
// cerr<<"hs = "<<hs<<endl;
    
    const Mint ans = linearRecurrenceAt(hs, cs, M);
    printf("%u\n", ans.x);
    
#ifdef LOCAL
for(Int m=0;m<len;++m)cerr<<linearRecurrenceAt(hs,cs,m)<<" ";
cerr<<endl;
#endif
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 8ms
memory: 15524kb

input:

2 3
1 1
1 1

output:

18

result:

ok 1 number(s): "18"

Test #2:

score: 0
Accepted
time: 7ms
memory: 15476kb

input:

3 4
1 2 3
1 3 2

output:

180

result:

ok 1 number(s): "180"

Test #3:

score: 0
Accepted
time: 3ms
memory: 15520kb

input:

2 10000
1 1
1 1

output:

219175682

result:

ok 1 number(s): "219175682"

Test #4:

score: 0
Accepted
time: 6ms
memory: 15476kb

input:

3 10000
1 2 3
1 3 2

output:

22506633

result:

ok 1 number(s): "22506633"

Test #5:

score: 0
Accepted
time: 5ms
memory: 15532kb

input:

2 100000
1 1
1 1

output:

545932818

result:

ok 1 number(s): "545932818"

Test #6:

score: 0
Accepted
time: 6ms
memory: 15536kb

input:

3 100000
1 2 3
1 3 2

output:

57531357

result:

ok 1 number(s): "57531357"

Test #7:

score: 0
Accepted
time: 12ms
memory: 15524kb

input:

2 1000000
1 1
1 1

output:

573543093

result:

ok 1 number(s): "573543093"

Test #8:

score: 0
Accepted
time: 12ms
memory: 15480kb

input:

3 1000000
1 2 3
1 3 2

output:

403805847

result:

ok 1 number(s): "403805847"

Test #9:

score: 0
Accepted
time: 102ms
memory: 16188kb

input:

100 10
611820018 75283856 260526347 643767967 631268284 65648470 256718930 106368182 843661377 781313189 595194538 910990296 902258405 714186458 994234477 224492449 18296975 46262610 20991790 104288095 566832326 611425812 406579987 77488677 292658024 472980409 639810931 869525405 785145 7334819 9037...

output:

398533280

result:

ok 1 number(s): "398533280"

Test #10:

score: 0
Accepted
time: 95ms
memory: 16304kb

input:

100 1000
337861296 954983610 933984767 158413395 236083015 753884779 480227722 932008977 222135711 538427797 248038326 483405605 988416942 772990315 109612622 13993552 741972144 431449344 885517243 122926909 624917994 844993934 728622505 562105730 55499197 550328547 339918311 264032815 950626134 179...

output:

73138730

result:

ok 1 number(s): "73138730"

Test #11:

score: 0
Accepted
time: 155ms
memory: 16692kb

input:

100 1000000
903000973 111290548 476765164 551975212 417263983 767801442 332671705 278870842 201796633 763068216 960266344 26482099 425400417 95404984 465717382 564861093 884664057 821929061 592534023 30343744 936134428 561670930 15703251 993624219 870390001 723109936 981318197 656667259 663611325 79...

output:

184586019

result:

ok 1 number(s): "184586019"

Test #12:

score: 0
Accepted
time: 252ms
memory: 16648kb

input:

100 1000000000
604297456 257710428 680778188 39374726 220956130 149356685 838936858 237228921 460651102 14915933 281581197 546327552 891296342 578540918 257819754 952356650 464523259 475942266 855600625 501203770 866723687 956420345 653224524 350671741 193934342 737912261 157584420 514316163 5731646...

output:

319681565

result:

ok 1 number(s): "319681565"

Test #13:

score: 0
Accepted
time: 46ms
memory: 15764kb

input:

47 939103
460209796 923769396 497130455 808750267 18580352 834685802 844939762 655958719 739484445 425067482 799235401 220463915 346712582 882586918 650792581 69525904 386758289 448868866 132258056 596695126 476338507 436189171 608073202 431881768 654354303 965133883 322147241 729417140 303007941 43...

output:

697877594

result:

ok 1 number(s): "697877594"

Test #14:

score: 0
Accepted
time: 8ms
memory: 15472kb

input:

5 20320
382406383 333353114 214385221 941605706 957498024
619083842 292772465 335037867 449241457 284312462

output:

648153718

result:

ok 1 number(s): "648153718"

Test #15:

score: 0
Accepted
time: 6ms
memory: 15488kb

input:

10 203
113356422 444048748 334760365 168456429 484325461 304651414 551964556 490305389 320866640 344214227
59919841 828724485 840698445 104730082 572733049 659837626 200222587 316651460 461116205 929846700

output:

860154954

result:

ok 1 number(s): "860154954"

Test #16:

score: 0
Accepted
time: 130ms
memory: 16564kb

input:

100 23203
590215812 330919503 361804049 160841393 202577205 767474814 261396779 534556107 11546512 315928375 548186686 418841505 971313703 728695556 991214364 553240798 294967304 944071947 960112453 266119259 515272798 476117665 854261275 247679517 137587630 103865755 561276374 970920554 9978160 549...

output:

319899104

result:

ok 1 number(s): "319899104"

Test #17:

score: 0
Accepted
time: 62ms
memory: 15776kb

input:

47 1000000000
661236701 626011023 653401016 269507301 947858324 488679806 682307210 795514627 747127946 933364412 126186059 532060957 912405701 875433550 878553905 363499560 534441266 584528443 703237317 73856741 96530866 645865395 853378035 916787403 685813713 118694785 912869318 420101396 63662492...

output:

975440921

result:

ok 1 number(s): "975440921"

Test #18:

score: 0
Accepted
time: 216ms
memory: 17400kb

input:

147 10
462565524 147218320 961380299 517841640 474426942 690678806 708345902 138526412 594824170 711085626 400440944 547048987 257456629 858639492 731548623 743813006 821987881 212909550 986929898 302432282 797126565 348883326 723121207 65669843 523779740 462686631 179539669 863701865 324988545 8236...

output:

842067007

result:

ok 1 number(s): "842067007"

Test #19:

score: 0
Accepted
time: 513ms
memory: 21048kb

input:

250 1000
359444936 577808352 826049210 937279560 968237772 846436826 63317947 327295422 805344944 972799416 11317310 147013950 783864555 646400672 181338678 200051004 380780464 782975995 907350103 984833619 119607074 682306803 697289898 147681694 652404823 348889915 901738893 696974445 693347094 616...

output:

441591881

result:

ok 1 number(s): "441591881"

Test #20:

score: 0
Accepted
time: 642ms
memory: 21600kb

input:

200 1000000
874654868 716961475 190056783 217613512 270419311 928606069 110795081 797619047 5066043 622162200 233468286 849682819 932605405 421878748 971561346 522911058 820676673 541104759 868007035 915383864 505494377 249870500 843072321 537442117 621304223 279155014 364150264 753394165 586053537 ...

output:

718830226

result:

ok 1 number(s): "718830226"

Test #21:

score: 0
Accepted
time: 994ms
memory: 21268kb

input:

190 1000000000
292432717 113243080 782850858 172875356 666459177 694100208 895717171 654232213 811149478 692945443 132670383 501884040 952942129 647574489 801625042 7020933 497251380 57436006 898832679 504715288 374768882 690448784 733992082 836263798 169618991 932677069 868515629 488357250 6225605 ...

output:

262821982

result:

ok 1 number(s): "262821982"

Test #22:

score: 0
Accepted
time: 954ms
memory: 25332kb

input:

300 10
141416754 840193279 939495438 894074444 357961599 893355088 946771006 468551335 988010195 578425753 45582485 678562805 842752189 299012071 877195300 942962308 312940913 48091926 593525589 431117014 585154959 534766048 914518145 306770747 91708675 676599371 136242034 913227941 655846387 546182...

output:

477817221

result:

ok 1 number(s): "477817221"

Test #23:

score: 0
Accepted
time: 968ms
memory: 25412kb

input:

300 1000
881842413 86529938 693226698 20757197 164509906 310379730 597581323 380048694 772704893 160215562 406792873 97226450 513243503 324045599 972495119 257440375 826958761 280401032 425640175 326986758 420258228 298452017 710062261 224951134 491316417 407531361 26721586 472379648 484051640 16798...

output:

732490438

result:

ok 1 number(s): "732490438"

Test #24:

score: 0
Accepted
time: 1309ms
memory: 28728kb

input:

300 1000000
100579760 892289966 263679968 936720216 747697319 399346310 126202533 776869874 580862239 418953789 573536832 409884862 171308486 98937954 131377655 991658975 439071483 512301561 944105267 932299071 894863189 263184189 66678588 477820447 34975336 982457276 71778919 387114327 308627278 20...

output:

678269002

result:

ok 1 number(s): "678269002"

Test #25:

score: 0
Accepted
time: 2091ms
memory: 28768kb

input:

300 1000000000
844189155 306246728 764486702 296212354 682237724 995426531 484985870 919411723 19081297 425060640 679557693 229668380 370315094 453252907 409487440 383346311 304432744 706524934 456058788 261585079 888251458 726586849 720010611 433565812 778508674 751679601 496382059 474420983 254876...

output:

255690783

result:

ok 1 number(s): "255690783"