QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#666251#9174. Game DesignmaspyAC ✓78ms4040kbC++2319.8kb2024-10-22 17:20:372024-10-22 17:20:46

Judging History

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

  • [2024-10-22 17:20:46]
  • 评测
  • 测评结果:AC
  • 用时:78ms
  • 内存:4040kb
  • [2024-10-22 17:20:37]
  • 提交

answer

#line 1 "/home/maspy/compro/library/my_template.hpp"
#if defined(LOCAL)
#include <my_template_compiled.hpp>
#else

// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("Ofast,unroll-loops")
// いまの CF だとこれ入れると動かない?
// #pragma GCC target("avx2,popcnt")

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i128 = __int128;
using u128 = unsigned __int128;
using f128 = __float128;

template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'010'000'000;
template <>
constexpr ll infty<ll> = 2'020'000'000'000'000'000;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * 2'000'000'000'000'000'000;
template <>
constexpr double infty<double> = infty<ll>;
template <>
constexpr long double infty<long double> = infty<ll>;

using pi = pair<ll, ll>;
using vi = vector<ll>;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vc<T>>;
template <class T>
using vvvc = vector<vvc<T>>;
template <class T>
using vvvvc = vector<vvvc<T>>;
template <class T>
using vvvvvc = vector<vvvvc<T>>;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;

#define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...) \
  vector<vector<vector<vector<type>>>> name(a, vector<vector<vector<type>>>(b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))

// https://trap.jp/post/1224/
#define FOR1(a) for (ll _ = 0; _ < ll(a); ++_)
#define FOR2(i, a) for (ll i = 0; i < ll(a); ++i)
#define FOR3(i, a, b) for (ll i = a; i < ll(b); ++i)
#define FOR4(i, a, b, c) for (ll i = a; i < ll(b); i += (c))
#define FOR1_R(a) for (ll i = (a)-1; i >= ll(0); --i)
#define FOR2_R(i, a) for (ll i = (a)-1; i >= ll(0); --i)
#define FOR3_R(i, a, b) for (ll i = (b)-1; i >= ll(a); --i)
#define overload4(a, b, c, d, e, ...) e
#define overload3(a, b, c, d, ...) d
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FOR_R(...) overload3(__VA_ARGS__, FOR3_R, FOR2_R, FOR1_R)(__VA_ARGS__)

#define FOR_subset(t, s) for (ll t = (s); t >= 0; t = (t == 0 ? -1 : (t - 1) & (s)))
#define all(x) x.begin(), x.end()
#define len(x) ll(x.size())
#define elif else if

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second

#define stoi stoll

int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }
int popcnt_mod_2(int x) { return __builtin_parity(x); }
int popcnt_mod_2(u32 x) { return __builtin_parity(x); }
int popcnt_mod_2(ll x) { return __builtin_parityll(x); }
int popcnt_mod_2(u64 x) { return __builtin_parityll(x); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 1, 2)
int topbit(int x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(u32 x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
int topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 0, 2)
int lowbit(int x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(u32 x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
int lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }

template <typename T>
T floor(T a, T b) {
  return a / b - (a % b && (a ^ b) < 0);
}
template <typename T>
T ceil(T x, T y) {
  return floor(x + y - 1, y);
}
template <typename T>
T bmod(T x, T y) {
  return x - y * floor(x, y);
}
template <typename T>
pair<T, T> divmod(T x, T y) {
  T q = floor(x, y);
  return {q, x - q * y};
}

template <typename T, typename U>
T SUM(const vector<U> &A) {
  T sm = 0;
  for (auto &&a: A) sm += a;
  return sm;
}

#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define UNIQUE(x) sort(all(x)), x.erase(unique(all(x)), x.end()), x.shrink_to_fit()

template <typename T>
T POP(deque<T> &que) {
  T a = que.front();
  que.pop_front();
  return a;
}
template <typename T>
T POP(pq<T> &que) {
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(pqg<T> &que) {
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(vc<T> &que) {
  T a = que.back();
  que.pop_back();
  return a;
}

template <typename F>
ll binary_search(F check, ll ok, ll ng, bool check_ok = true) {
  if (check_ok) assert(check(ok));
  while (abs(ok - ng) > 1) {
    auto x = (ng + ok) / 2;
    (check(x) ? ok : ng) = x;
  }
  return ok;
}
template <typename F>
double binary_search_real(F check, double ok, double ng, int iter = 100) {
  FOR(iter) {
    double x = (ok + ng) / 2;
    (check(x) ? ok : ng) = x;
  }
  return (ok + ng) / 2;
}

template <class T, class S>
inline bool chmax(T &a, const S &b) {
  return (a < b ? a = b, 1 : 0);
}
template <class T, class S>
inline bool chmin(T &a, const S &b) {
  return (a > b ? a = b, 1 : 0);
}

// ? は -1
vc<int> s_to_vi(const string &S, char first_char) {
  vc<int> A(S.size());
  FOR(i, S.size()) { A[i] = (S[i] != '?' ? S[i] - first_char : -1); }
  return A;
}

template <typename T, typename U>
vector<T> cumsum(vector<U> &A, int off = 1) {
  int N = A.size();
  vector<T> B(N + 1);
  FOR(i, N) { B[i + 1] = B[i] + A[i]; }
  if (off == 0) B.erase(B.begin());
  return B;
}

// stable sort
template <typename T>
vector<int> argsort(const vector<T> &A) {
  vector<int> ids(len(A));
  iota(all(ids), 0);
  sort(all(ids), [&](int i, int j) { return (A[i] == A[j] ? i < j : A[i] < A[j]); });
  return ids;
}

// A[I[0]], A[I[1]], ...
template <typename T>
vc<T> rearrange(const vc<T> &A, const vc<int> &I) {
  vc<T> B(len(I));
  FOR(i, len(I)) B[i] = A[I[i]];
  return B;
}

template <typename T, typename... Vectors>
void concat(vc<T> &first, const Vectors &... others) {
  vc<T> &res = first;
  (res.insert(res.end(), others.begin(), others.end()), ...);
}
#endif
#line 1 "/home/maspy/compro/library/other/io.hpp"
#define FASTIO
#include <unistd.h>

// https://judge.yosupo.jp/submission/21623
namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf
uint32_t pil = 0, pir = 0, por = 0;

struct Pre {
  char num[10000][4];
  constexpr Pre() : num() {
    for (int i = 0; i < 10000; i++) {
      int n = i;
      for (int j = 3; j >= 0; j--) {
        num[i][j] = n % 10 | '0';
        n /= 10;
      }
    }
  }
} constexpr pre;

inline void load() {
  memcpy(ibuf, ibuf + pil, pir - pil);
  pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
  pil = 0;
  if (pir < SZ) ibuf[pir++] = '\n';
}

inline void flush() {
  fwrite(obuf, 1, por, stdout);
  por = 0;
}

void rd(char &c) {
  do {
    if (pil + 1 > pir) load();
    c = ibuf[pil++];
  } while (isspace(c));
}

void rd(string &x) {
  x.clear();
  char c;
  do {
    if (pil + 1 > pir) load();
    c = ibuf[pil++];
  } while (isspace(c));
  do {
    x += c;
    if (pil == pir) load();
    c = ibuf[pil++];
  } while (!isspace(c));
}

template <typename T>
void rd_real(T &x) {
  string s;
  rd(s);
  x = stod(s);
}

template <typename T>
void rd_integer(T &x) {
  if (pil + 100 > pir) load();
  char c;
  do
    c = ibuf[pil++];
  while (c < '-');
  bool minus = 0;
  if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
    if (c == '-') { minus = 1, c = ibuf[pil++]; }
  }
  x = 0;
  while ('0' <= c) { x = x * 10 + (c & 15), c = ibuf[pil++]; }
  if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
    if (minus) x = -x;
  }
}

void rd(int &x) { rd_integer(x); }
void rd(ll &x) { rd_integer(x); }
void rd(i128 &x) { rd_integer(x); }
void rd(u32 &x) { rd_integer(x); }
void rd(u64 &x) { rd_integer(x); }
void rd(u128 &x) { rd_integer(x); }
void rd(double &x) { rd_real(x); }
void rd(long double &x) { rd_real(x); }
void rd(f128 &x) { rd_real(x); }

template <class T, class U>
void rd(pair<T, U> &p) {
  return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T>
void rd_tuple(T &t) {
  if constexpr (N < std::tuple_size<T>::value) {
    auto &x = std::get<N>(t);
    rd(x);
    rd_tuple<N + 1>(t);
  }
}
template <class... T>
void rd(tuple<T...> &tpl) {
  rd_tuple(tpl);
}

template <size_t N = 0, typename T>
void rd(array<T, N> &x) {
  for (auto &d: x) rd(d);
}
template <class T>
void rd(vc<T> &x) {
  for (auto &d: x) rd(d);
}

void read() {}
template <class H, class... T>
void read(H &h, T &... t) {
  rd(h), read(t...);
}

void wt(const char c) {
  if (por == SZ) flush();
  obuf[por++] = c;
}
void wt(const string s) {
  for (char c: s) wt(c);
}
void wt(const char *s) {
  size_t len = strlen(s);
  for (size_t i = 0; i < len; i++) wt(s[i]);
}

template <typename T>
void wt_integer(T x) {
  if (por > SZ - 100) flush();
  if (x < 0) { obuf[por++] = '-', x = -x; }
  int outi;
  for (outi = 96; x >= 10000; outi -= 4) {
    memcpy(out + outi, pre.num[x % 10000], 4);
    x /= 10000;
  }
  if (x >= 1000) {
    memcpy(obuf + por, pre.num[x], 4);
    por += 4;
  } else if (x >= 100) {
    memcpy(obuf + por, pre.num[x] + 1, 3);
    por += 3;
  } else if (x >= 10) {
    int q = (x * 103) >> 10;
    obuf[por] = q | '0';
    obuf[por + 1] = (x - q * 10) | '0';
    por += 2;
  } else
    obuf[por++] = x | '0';
  memcpy(obuf + por, out + outi + 4, 96 - outi);
  por += 96 - outi;
}

template <typename T>
void wt_real(T x) {
  ostringstream oss;
  oss << fixed << setprecision(15) << double(x);
  string s = oss.str();
  wt(s);
}

void wt(int x) { wt_integer(x); }
void wt(ll x) { wt_integer(x); }
void wt(i128 x) { wt_integer(x); }
void wt(u32 x) { wt_integer(x); }
void wt(u64 x) { wt_integer(x); }
void wt(u128 x) { wt_integer(x); }
void wt(double x) { wt_real(x); }
void wt(long double x) { wt_real(x); }
void wt(f128 x) { wt_real(x); }

template <class T, class U>
void wt(const pair<T, U> val) {
  wt(val.first);
  wt(' ');
  wt(val.second);
}
template <size_t N = 0, typename T>
void wt_tuple(const T t) {
  if constexpr (N < std::tuple_size<T>::value) {
    if constexpr (N > 0) { wt(' '); }
    const auto x = std::get<N>(t);
    wt(x);
    wt_tuple<N + 1>(t);
  }
}
template <class... T>
void wt(tuple<T...> tpl) {
  wt_tuple(tpl);
}
template <class T, size_t S>
void wt(const array<T, S> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}
template <class T>
void wt(const vector<T> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}

void print() { wt('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
  wt(head);
  if (sizeof...(Tail)) wt(' ');
  print(forward<Tail>(tail)...);
}

// gcc expansion. called automaticall after main.
void __attribute__((destructor)) _d() { flush(); }
} // namespace fastio
using fastio::read;
using fastio::print;
using fastio::flush;

#if defined(LOCAL)
#define SHOW(...) SHOW_IMPL(__VA_ARGS__, SHOW6, SHOW5, SHOW4, SHOW3, SHOW2, SHOW1)(__VA_ARGS__)
#define SHOW_IMPL(_1, _2, _3, _4, _5, _6, NAME, ...) NAME
#define SHOW1(x) print(#x, "=", (x)), flush()
#define SHOW2(x, y) print(#x, "=", (x), #y, "=", (y)), flush()
#define SHOW3(x, y, z) print(#x, "=", (x), #y, "=", (y), #z, "=", (z)), flush()
#define SHOW4(x, y, z, w) print(#x, "=", (x), #y, "=", (y), #z, "=", (z), #w, "=", (w)), flush()
#define SHOW5(x, y, z, w, v) print(#x, "=", (x), #y, "=", (y), #z, "=", (z), #w, "=", (w), #v, "=", (v)), flush()
#define SHOW6(x, y, z, w, v, u) print(#x, "=", (x), #y, "=", (y), #z, "=", (z), #w, "=", (w), #v, "=", (v), #u, "=", (u)), flush()
#else
#define SHOW(...)
#endif

#define INT(...)   \
  int __VA_ARGS__; \
  read(__VA_ARGS__)
#define LL(...)   \
  ll __VA_ARGS__; \
  read(__VA_ARGS__)
#define U32(...)   \
  u32 __VA_ARGS__; \
  read(__VA_ARGS__)
#define U64(...)   \
  u64 __VA_ARGS__; \
  read(__VA_ARGS__)
#define STR(...)      \
  string __VA_ARGS__; \
  read(__VA_ARGS__)
#define CHAR(...)   \
  char __VA_ARGS__; \
  read(__VA_ARGS__)
#define DBL(...)      \
  double __VA_ARGS__; \
  read(__VA_ARGS__)

#define VEC(type, name, size) \
  vector<type> name(size);    \
  read(name)
#define VV(type, name, h, w)                     \
  vector<vector<type>> name(h, vector<type>(w)); \
  read(name)

void YES(bool t = 1) { print(t ? "YES" : "NO"); }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { print(t ? "Yes" : "No"); }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { print(t ? "yes" : "no"); }
void no(bool t = 1) { yes(!t); }
#line 3 "main.cpp"

#line 2 "/home/maspy/compro/library/mod/modint_common.hpp"

struct has_mod_impl {
  template <class T>
  static auto check(T &&x) -> decltype(x.get_mod(), std::true_type{});
  template <class T>
  static auto check(...) -> std::false_type;
};

template <class T>
class has_mod : public decltype(has_mod_impl::check<T>(std::declval<T>())) {};

template <typename mint>
mint inv(int n) {
  static const int mod = mint::get_mod();
  static vector<mint> dat = {0, 1};
  assert(0 <= n);
  if (n >= mod) n %= mod;
  while (len(dat) <= n) {
    int k = len(dat);
    int q = (mod + k - 1) / k;
    dat.eb(dat[k * q - mod] * mint::raw(q));
  }
  return dat[n];
}

template <typename mint>
mint fact(int n) {
  static const int mod = mint::get_mod();
  assert(0 <= n && n < mod);
  static vector<mint> dat = {1, 1};
  while (len(dat) <= n) dat.eb(dat[len(dat) - 1] * mint::raw(len(dat)));
  return dat[n];
}

template <typename mint>
mint fact_inv(int n) {
  static vector<mint> dat = {1, 1};
  if (n < 0) return mint(0);
  while (len(dat) <= n) dat.eb(dat[len(dat) - 1] * inv<mint>(len(dat)));
  return dat[n];
}

template <class mint, class... Ts>
mint fact_invs(Ts... xs) {
  return (mint(1) * ... * fact_inv<mint>(xs));
}

template <typename mint, class Head, class... Tail>
mint multinomial(Head &&head, Tail &&... tail) {
  return fact<mint>(head) * fact_invs<mint>(std::forward<Tail>(tail)...);
}

template <typename mint>
mint C_dense(int n, int k) {
  static vvc<mint> C;
  static int H = 0, W = 0;
  auto calc = [&](int i, int j) -> mint {
    if (i == 0) return (j == 0 ? mint(1) : mint(0));
    return C[i - 1][j] + (j ? C[i - 1][j - 1] : 0);
  };
  if (W <= k) {
    FOR(i, H) {
      C[i].resize(k + 1);
      FOR(j, W, k + 1) { C[i][j] = calc(i, j); }
    }
    W = k + 1;
  }
  if (H <= n) {
    C.resize(n + 1);
    FOR(i, H, n + 1) {
      C[i].resize(W);
      FOR(j, W) { C[i][j] = calc(i, j); }
    }
    H = n + 1;
  }
  return C[n][k];
}

template <typename mint, bool large = false, bool dense = false>
mint C(ll n, ll k) {
  assert(n >= 0);
  if (k < 0 || n < k) return 0;
  if constexpr (dense) return C_dense<mint>(n, k);
  if constexpr (!large) return multinomial<mint>(n, k, n - k);
  k = min(k, n - k);
  mint x(1);
  FOR(i, k) x *= mint(n - i);
  return x * fact_inv<mint>(k);
}

template <typename mint, bool large = false>
mint C_inv(ll n, ll k) {
  assert(n >= 0);
  assert(0 <= k && k <= n);
  if (!large) return fact_inv<mint>(n) * fact<mint>(k) * fact<mint>(n - k);
  return mint(1) / C<mint, 1>(n, k);
}

// [x^d](1-x)^{-n}
template <typename mint, bool large = false, bool dense = false>
mint C_negative(ll n, ll d) {
  assert(n >= 0);
  if (d < 0) return mint(0);
  if (n == 0) { return (d == 0 ? mint(1) : mint(0)); }
  return C<mint, large, dense>(n + d - 1, d);
}
#line 3 "/home/maspy/compro/library/mod/modint.hpp"

template <int mod>
struct modint {
  static constexpr u32 umod = u32(mod);
  static_assert(umod < u32(1) << 31);
  u32 val;

  static modint raw(u32 v) {
    modint x;
    x.val = v;
    return x;
  }
  constexpr modint() : val(0) {}
  constexpr modint(u32 x) : val(x % umod) {}
  constexpr modint(u64 x) : val(x % umod) {}
  constexpr modint(u128 x) : val(x % umod) {}
  constexpr modint(int x) : val((x %= mod) < 0 ? x + mod : x){};
  constexpr modint(ll x) : val((x %= mod) < 0 ? x + mod : x){};
  constexpr modint(i128 x) : val((x %= mod) < 0 ? x + mod : x){};
  bool operator<(const modint &other) const { return val < other.val; }
  modint &operator+=(const modint &p) {
    if ((val += p.val) >= umod) val -= umod;
    return *this;
  }
  modint &operator-=(const modint &p) {
    if ((val += umod - p.val) >= umod) val -= umod;
    return *this;
  }
  modint &operator*=(const modint &p) {
    val = u64(val) * p.val % umod;
    return *this;
  }
  modint &operator/=(const modint &p) {
    *this *= p.inverse();
    return *this;
  }
  modint operator-() const { return modint::raw(val ? mod - val : u32(0)); }
  modint operator+(const modint &p) const { return modint(*this) += p; }
  modint operator-(const modint &p) const { return modint(*this) -= p; }
  modint operator*(const modint &p) const { return modint(*this) *= p; }
  modint operator/(const modint &p) const { return modint(*this) /= p; }
  bool operator==(const modint &p) const { return val == p.val; }
  bool operator!=(const modint &p) const { return val != p.val; }
  modint inverse() const {
    int a = val, b = mod, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b), swap(u -= t * v, v);
    }
    return modint(u);
  }
  modint pow(ll n) const {
    assert(n >= 0);
    modint ret(1), mul(val);
    while (n > 0) {
      if (n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
  static constexpr int get_mod() { return mod; }
  // (n, r), r は 1 の 2^n 乗根
  static constexpr pair<int, int> ntt_info() {
    if (mod == 120586241) return {20, 74066978};
    if (mod == 167772161) return {25, 17};
    if (mod == 469762049) return {26, 30};
    if (mod == 754974721) return {24, 362};
    if (mod == 880803841) return {23, 211};
    if (mod == 943718401) return {22, 663003469};
    if (mod == 998244353) return {23, 31};
    if (mod == 1004535809) return {21, 836905998};
    if (mod == 1045430273) return {20, 363};
    if (mod == 1051721729) return {20, 330};
    if (mod == 1053818881) return {20, 2789};
    return {-1, -1};
  }
  static constexpr bool can_ntt() { return ntt_info().fi != -1; }
};

#ifdef FASTIO
template <int mod>
void rd(modint<mod> &x) {
  fastio::rd(x.val);
  x.val %= mod;
  // assert(0 <= x.val && x.val < mod);
}
template <int mod>
void wt(modint<mod> x) {
  fastio::wt(x.val);
}
#endif

using modint107 = modint<1000000007>;
using modint998 = modint<998244353>;
#line 5 "main.cpp"

// 0 なら右に対応させる

using mint = modint998;
void solve() {
  STR(S);
  ll N = len(S);
  vc<mint> dp(1);
  dp[0] = 1;
  FOR(n, N) {
    vc<mint> newdp(n + 2);
    // 左に行く, 左から来る
    if (S[n] == '1') {
      FOR(k, 1, n + 1) { newdp[k - 1] += dp[k] * mint(k * k); }
    }
    // 左に行く, 右から来る
    if (S[n] == '1') {
      FOR(k, 1, n + 1) { newdp[k] += dp[k] * mint(k); }
    }
    // 右に行く, 左から来る
    FOR(k, 1, n + 1) { newdp[k] += dp[k] * mint(k); }
    // 右に行く, 右から来る
    FOR(k, 0, n + 1) { newdp[k + 1] += dp[k]; }
    swap(dp, newdp);
  }
  print(dp[0]);
}

signed main() {
  INT(T);
  FOR(T) solve();
}

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3672kb

input:

4
0101
1010010010001010
11111
10100100011000010010101001001001

output:

3
0
44
393298077

result:

ok 4 number(s): "3 0 44 393298077"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3628kb

input:

4
01
11
10
00

output:

1
1
0
0

result:

ok 4 number(s): "1 1 0 0"

Test #3:

score: 0
Accepted
time: 1ms
memory: 3924kb

input:

8
011
110
100
000
010
101
111
001

output:

2
0
0
0
0
1
2
1

result:

ok 8 numbers

Test #4:

score: 0
Accepted
time: 1ms
memory: 3512kb

input:

16
0111
0110
0000
1001
1100
0011
0100
1110
1011
0001
1000
0010
1111
0101
1010
1101

output:

9
0
0
1
0
6
0
0
6
1
0
0
9
3
0
3

result:

ok 16 numbers

Test #5:

score: 0
Accepted
time: 1ms
memory: 3856kb

input:

32
01100
10010
11011
10100
00100
01010
10000
01111
11000
01001
00101
00011
11001
11111
10001
00000
00111
11101
11010
10110
10111
01101
10011
11100
01110
00001
01000
10101
01011
00010
00110
11110

output:

0
0
22
0
0
0
0
44
0
3
7
14
3
44
1
0
33
11
0
0
33
11
14
0
0
1
0
7
22
0
0
0

result:

ok 32 numbers

Test #6:

score: 0
Accepted
time: 1ms
memory: 3964kb

input:

64
001000
011100
101100
001101
011110
100000
000000
001111
000101
110111
010001
101111
001001
011111
111100
010011
100010
000001
010110
111111
111101
110101
111010
011010
110110
101000
101110
010010
011011
010000
100110
001010
101010
100111
100100
100101
110000
010111
011000
110011
000100
101001
111...

output:

0
0
0
39
0
0
0
212
15
159
3
212
7
265
0
50
0
1
0
265
53
25
0
0
0
0
0
0
106
0
0
0
0
117
0
15
0
159
0
50
0
7
0
0
25
53
3
117
30
11
39
78
0
0
30
0
0
1
0
11
78
106
0
0

result:

ok 64 numbers

Test #7:

score: 0
Accepted
time: 1ms
memory: 3740kb

input:

128
0111100
0110000
1010010
1001001
1010110
0011101
0100100
1100110
0110101
1001110
0101110
1111011
0100101
0111110
1001011
0110010
1111000
0101111
1101011
1001000
1110100
1000011
1001111
1101000
0100000
0010010
1100000
1011000
0100111
1001101
1010111
0111101
1110011
0101011
0001110
0010100
0011110
...

output:

0
0
0
15
0
245
0
0
117
0
0
618
53
0
262
0
0
1236
362
0
0
62
980
0
0
0
0
0
543
131
735
309
234
362
0
0
0
1545
0
11
7
1236
0
170
25
15
0
3
490
0
735
0
0
0
0
106
0
618
0
1854
85
393
0
0
106
0
7
31
0
62
39
0
31
0
53
0
0
927
0
0
927
39
0
0
170
0
543
980
393
0
0
25
0
0
0
262
11
0
1
0
0
0
3
0
131
309
0
53
...

result:

ok 128 numbers

Test #8:

score: 0
Accepted
time: 1ms
memory: 3680kb

input:

256
01101111
10001000
01111011
01100010
10101111
00100101
11111101
01010000
00111010
01101001
10001101
00101011
00100000
11000111
01001010
10111100
01000001
11001101
01110111
00101000
00100001
01101010
10101101
01101000
11111100
11000110
11001110
00011111
01010101
11101010
10110010
11111000
11011000...

output:

8476
0
4238
0
7028
177
2119
0
0
117
423
1626
0
1779
0
0
3
593
6357
0
7
0
813
0
0
0
0
8785
387
0
0
0
0
1097
0
0
0
0
0
0
0
0
0
0
0
0
3514
0
0
0
0
0
53
0
11
109
2194
126
0
423
5580
0
0
12714
0
2119
10595
2066
0
85
3099
0
0
0
0
0
0
8785
490
0
354
1186
554
1342
11
0
0
1269
39
387
0
0
0
0
25
671
0
0
2066
...

result:

ok 256 numbers

Test #9:

score: 0
Accepted
time: 1ms
memory: 3980kb

input:

512
011101111
100101011
001000111
000000011
111011100
111110010
000011111
001100011
001101100
110001101
100010001
000010000
010110100
111001110
010110010
000101010
000111100
000110011
001111010
000001100
010010001
100110010
101010000
110110101
010100101
000111000
000111001
011000111
011010011
000011...

output:

66748
7106
7827
254
0
0
48825
2194
0
1885
31
0
0
0
0
0
0
4650
0
0
53
0
0
2971
799
0
1097
9999
4366
0
671
28518
85554
11
0
23662
0
0
9094
0
0
0
0
569
5761
11831
4547
0
42777
0
0
59155
3759
0
15
7763
0
9094
5942
0
1033
0
813
9765
3770
1331
133496
3993
0
0
71295
0
53
0
31052
6123
5218
0
15526
0
0
0
999...

result:

ok 512 numbers

Test #10:

score: 0
Accepted
time: 1ms
memory: 3976kb

input:

500
1000111011
1110100001
0111111011
1110001101
0111100101
0110000101
0110100111
0001101011
1000001011
1001000111
1010011001
0110001001
1100011011
1110100101
1110000101
0001001111
1110111001
0011101010
1110001001
0110111111
0111101111
1011010001
1001010111
1001011101
1110110011
1101011111
1100110001...

output:

106426
117
296658
10489
9403
1013
90825
62978
8238
33639
2609
501
52542
4483
1013
169404
9403
0
501
889974
593316
529
127053
42351
39678
553585
593
188678
129523
221
2325
0
245
24543
39110
741645
221
0
11831
2026
22267
129523
388569
39
0
10790
1334961
12839
18341
7383
6975
24543
85
9481
3
459555
234...

result:

ok 500 numbers

Test #11:

score: 0
Accepted
time: 2ms
memory: 3984kb

input:

50
1100100010011000000010000010100000000000000000100000100000000000110100000000011010110010010000000001
0001000000010000000010000000000001000001000001011011100001001000101000000000100000000001000000100001
00100000000000000000000001010000000010010000001000100000011010000000110010000000100010000010001...

output:

205708860
923855108
919861840
547941024
630835913
963096460
557602835
220618001
647925838
0
0
47656261
460024445
0
838886692
191295282
499427902
294750324
654015592
0
593262022
707533601
157943159
928642837
696324035
245239519
808714077
711940617
747899832
118533868
878420264
806102755
395501450
355...

result:

ok 50 numbers

Test #12:

score: 0
Accepted
time: 2ms
memory: 3684kb

input:

50
0000011110010101000001001100000011001000010000111111000100000110101001011000101000100010000010110001
1011111000000100111011001010111000100010111110000000100110100100110111110100010011000101101111011100
10011010101100110101011101000100011110110011010100101111000111101100100101000011100010001100010...

output:

900268216
0
844603406
236796635
407522154
226699036
0
190239333
631618284
0
327246223
0
20559964
745508700
637737581
65478876
361504280
91157130
196682122
70737081
7244489
701018137
598065124
483954599
0
523352186
453684381
465782465
391157840
511431972
69450817
373878062
708107432
174222661
1967386...

result:

ok 50 numbers

Test #13:

score: 0
Accepted
time: 2ms
memory: 3748kb

input:

50
0011011110110110101100011111101001100110111110111011000011011110110011111100001010111111101111000111
1110010111111011111010011011100110001110101101110101110010111100110100101110111110110001111111010111
10101100000111000100001110111110011000111111000010111011111100010010101111001011010100111001110...

output:

497197651
976783133
352701285
514000197
136889040
191643872
784167119
275459708
939879193
701390938
470597025
442500414
768600751
672634738
645103426
430371225
0
466151127
0
472821930
945035312
0
498462764
369675272
722536547
0
794766856
682790685
578261000
838414952
106398218
99771164
681081103
949...

result:

ok 50 numbers

Test #14:

score: 0
Accepted
time: 2ms
memory: 3688kb

input:

50
1111101100111111111111011011001111100111101111110111111101101111111111110101111111111111111101110111
0110101100101100001111010111111111110110110010111111111111011110110011111111101111111111011111101101
11110111101110110111110110111110111110011110101111111111110101111110111011100010011100111111001...

output:

23606791
6373643
730292083
778994470
613158198
728025270
374269904
839367687
267381083
171300918
466325654
185771633
369673438
786338255
211219474
743203244
669692205
441307951
346011798
813717905
359257821
700939913
416208962
791306165
816414602
112231768
636885860
703147739
733175558
140559786
957...

result:

ok 50 numbers

Test #15:

score: 0
Accepted
time: 31ms
memory: 3832kb

input:

1
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

1

result:

ok 1 number(s): "1"

Test #16:

score: 0
Accepted
time: 40ms
memory: 3872kb

input:

1
0000100000000000000100000000011100000000111000011111010001100001000000100000100000000100000000010000100000101001100000000000000000000000001000000000101001000000000000000011000100101010000000000000000010000100000101000000000000000000000001010001010101010100101000100000000010101000000000000010010100...

output:

937021270

result:

ok 1 number(s): "937021270"

Test #17:

score: 0
Accepted
time: 50ms
memory: 4040kb

input:

1
0111000101100010011000100001001100100100000011011101000010110001110101101000001001001000011011100001100001010001000101010000010010101001101110111110001101010010010100001101011101011101110001101101110110011010000000110000010001000001100100010101011011010000000001010110001000101101101011000101100101...

output:

202924035

result:

ok 1 number(s): "202924035"

Test #18:

score: 0
Accepted
time: 60ms
memory: 3904kb

input:

1
0111011001110111111111001000111101110100100011111000100001111111111010101101101000010110111111111111111100100111101011110110100010110110111010111001111111111111010110001011111100010010011010010011100100110011011110101011101100101000100110100100110000111010011101101010101001111001001001110111011011...

output:

217010012

result:

ok 1 number(s): "217010012"

Test #19:

score: 0
Accepted
time: 69ms
memory: 3844kb

input:

1
0101111111111110011111101011101100110111111000101110111010010111110111101111110101011010010100111110111111111011001110111110110011111111111110000110111111010111010010111101101101110011111011111111111101101110101111111111111111111101111001110110111111111011111011111111110111111101111011110111111111...

output:

307502808

result:

ok 1 number(s): "307502808"

Test #20:

score: 0
Accepted
time: 78ms
memory: 3692kb

input:

1
1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

948020753

result:

ok 1 number(s): "948020753"

Test #21:

score: 0
Accepted
time: 1ms
memory: 3632kb

input:

1000
00010
11001
01001
11010
10011
10101
11011
00111
00011
10101
10001
11011
11111
01011
10111
01101
10111
10011
00111
01111
10101
10101
11111
11101
11100
10001
10011
11011
10101
10100
11011
00001
01111
10011
11011
10100
01001
01011
11101
11011
00011
00011
01001
01001
00001
10011
01011
10001
11011
1...

output:

0
3
3
0
14
7
22
33
14
7
1
22
44
22
33
11
33
14
33
44
7
7
44
11
0
1
14
22
7
0
22
1
44
14
22
0
3
22
11
22
14
14
3
3
1
14
22
1
22
3
0
44
7
22
44
0
33
11
44
33
33
1
7
11
7
22
1
14
7
1
7
1
3
44
14
14
22
22
7
11
11
3
22
22
22
7
7
3
22
3
0
0
14
3
1
7
14
22
1
7
44
44
22
0
1
44
3
11
0
44
14
22
11
22
1
22
1
1...

result:

ok 1000 numbers

Extra Test:

score: 0
Extra Test Passed