結果
問題 | No.2959 Dolls' Tea Party |
ユーザー | 👑 binap |
提出日時 | 2024-10-28 21:24:19 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 12,257 bytes |
コンパイル時間 | 5,000 ms |
コンパイル使用メモリ | 286,380 KB |
実行使用メモリ | 18,340 KB |
最終ジャッジ日時 | 2024-10-29 00:12:18 |
合計ジャッジ時間 | 9,885 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
13,644 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | AC | 2 ms
6,820 KB |
testcase_03 | AC | 2 ms
6,816 KB |
testcase_04 | AC | 2 ms
6,816 KB |
testcase_05 | AC | 2 ms
6,820 KB |
testcase_06 | TLE | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
ソースコード
#include<bits/stdc++.h> #include<atcoder/all> #define rep(i,n) for(int i=0;i<n;i++) using namespace std; using namespace atcoder; typedef long long ll; typedef vector<int> vi; typedef vector<long long> vl; typedef vector<vector<int>> vvi; typedef vector<vector<long long>> vvl; typedef long double ld; typedef pair<int, int> P; ostream& operator<<(ostream& os, const modint& a) {os << a.val(); return os;} template <int m> ostream& operator<<(ostream& os, const static_modint<m>& a) {os << a.val(); return os;} template <int m> ostream& operator<<(ostream& os, const dynamic_modint<m>& a) {os << a.val(); return os;} template<typename T> istream& operator>>(istream& is, vector<T>& v){int n = v.size(); assert(n > 0); rep(i, n) is >> v[i]; return is;} template<typename U, typename T> ostream& operator<<(ostream& os, const pair<U, T>& p){os << p.first << ' ' << p.second; return os;} template<typename T> ostream& operator<<(ostream& os, const vector<T>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : " "); return os;} template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : ""); return os;} template<typename T> ostream& operator<<(ostream& os, const set<T>& se){for(T x : se) os << x << " "; os << "\n"; return os;} template<typename T> ostream& operator<<(ostream& os, const unordered_set<T>& se){for(T x : se) os << x << " "; os << "\n"; return os;} template<typename S, auto op, auto e> ostream& operator<<(ostream& os, const atcoder::segtree<S, op, e>& seg){int n = seg.max_right(0, [](S){return true;}); rep(i, n) os << seg.get(i) << (i == n - 1 ? "\n" : " "); return os;} template<typename S, auto op, auto e, typename F, auto mapping, auto composition, auto id> ostream& operator<<(ostream& os, const atcoder::lazy_segtree<S, op, e, F, mapping, composition, id>& seg){int n = seg.max_right(0, [](S){return true;}); rep(i, n) os << seg.get(i) << (i == n - 1 ? "\n" : " "); return os;} template<typename T> void chmin(T& a, T b){a = min(a, b);} template<typename T> void chmax(T& a, T b){a = max(a, b);} using mint = modint998244353; // combination mod prime // https://youtu.be/8uowVvQ_-Mo?t=6002 // https://youtu.be/Tgd_zLfRZOQ?t=9928 struct modinv { int n; vector<mint> d; modinv(): n(2), d({0,1}) {} mint operator()(int i) { while (n <= i) d.push_back(-d[mint::mod()%n]*(mint::mod()/n)), ++n; return d[i]; } mint operator[](int i) const { return d[i];} } invs; struct modfact { int n; vector<mint> d; modfact(): n(2), d({1,1}) {} mint operator()(int i) { while (n <= i) d.push_back(d.back()*n), ++n; return d[i]; } mint operator[](int i) const { return d[i];} } facts; struct modfactinv { int n; vector<mint> d; modfactinv(): n(2), d({1,1}) {} mint operator()(int i) { while (n <= i) d.push_back(d.back()*invs(n)), ++n; return d[i]; } mint operator[](int i) const { return d[i];} } ifacts; mint comb(int n, int k) { if (n < k || k < 0) return 0; return facts(n)*ifacts(k)*ifacts(n-k); } template< typename T > struct FormalPowerSeries : vector< T > { using vector< T >::vector; using P = FormalPowerSeries; template<class...Args> FormalPowerSeries(Args...args): vector<T>(args...) {} FormalPowerSeries(initializer_list<T> a): vector<T>(a.begin(),a.end()) {} using MULT = function< P(P, P) >; static MULT &get_mult() { static MULT mult = [&](P a, P b){ P res(convolution(a, b)); return res; }; return mult; } static void set_fft(MULT f) { get_mult() = f; } void shrink() { while(this->size() && this->back() == T(0)) this->pop_back(); } P operator+(const P &r) const { return P(*this) += r; } P operator+(const T &v) const { return P(*this) += v; } P operator-(const P &r) const { return P(*this) -= r; } P operator-(const T &v) const { return P(*this) -= v; } P operator*(const P &r) const { return P(*this) *= r; } P operator*(const T &v) const { return P(*this) *= v; } P operator/(const P &r) const { return P(*this) /= r; } P operator%(const P &r) const { return P(*this) %= r; } P &operator+=(const P &r) { if(r.size() > this->size()) this->resize(r.size()); for(int i = 0; i < int(r.size()); i++) (*this)[i] += r[i]; return *this; } P &operator+=(const T &r) { if(this->empty()) this->resize(1); (*this)[0] += r; return *this; } P &operator-=(const P &r) { if(r.size() > this->size()) this->resize(r.size()); for(int i = 0; i < int(r.size()); i++) (*this)[i] -= r[i]; // shrink(); return *this; } P &operator-=(const T &r) { if(this->empty()) this->resize(1); (*this)[0] -= r; // shrink(); return *this; } P &operator*=(const T &v) { const int n = (int) this->size(); for(int k = 0; k < n; k++) (*this)[k] *= v; return *this; } P &operator*=(const P &r) { if(this->empty() || r.empty()) { this->clear(); return *this; } assert(get_mult() != nullptr); return *this = get_mult()(*this, r); } P &operator%=(const P &r) { return *this -= *this / r * r; } P operator-() const { P ret(this->size()); for(int i = 0; i < int(this->size()); i++) ret[i] = -(*this)[i]; return ret; } P &operator/=(const P &r) { if(this->size() < r.size()) { this->clear(); return *this; } int n = this->size() - r.size() + 1; return *this = (rev().pre(n) * r.rev().inv(n)).pre(n).rev(n); } P pre(int sz) const { return P(begin(*this), begin(*this) + min((int) this->size(), sz)); } P operator>>(int sz) const { if((int)this->size() <= sz) return {}; P ret(*this); ret.erase(ret.begin(), ret.begin() + sz); return ret; } P operator<<(int sz) const { P ret(*this); ret.insert(ret.begin(), sz, T(0)); return ret; } P rev(int deg = -1) const { P ret(*this); if(deg != -1) ret.resize(deg, T(0)); reverse(begin(ret), end(ret)); return ret; } P diff() const { const int n = (int) this->size(); P ret(max(0, n - 1)); for(int i = 1; i < n; i++) ret[i - 1] = (*this)[i] * T(i); return ret; } P integral() const { const int n = (int) this->size(); P ret(n + 1); ret[0] = T(0); for(int i = 0; i < n; i++) ret[i + 1] = (*this)[i] / T(i + 1); return ret; } // F(0) must not be 0 P inv(int deg = -1) const { assert(((*this)[0]) != T(0)); const int n = (int) this->size(); if(deg == -1) deg = n; P ret({T(1) / (*this)[0]}); for(int i = 1; i < deg; i <<= 1) { ret = (ret + ret - ret * ret * pre(i << 1)).pre(i << 1); } return ret.pre(deg); } /* P inv_special(int k, int deg = -1) const { // ret = 0 + x/f_1 P ret({0, T(k)}); for(int i = 1; (i >> 1) < deg; i <<= 1) { // F(G_i(x)) P fg = (((-ret.pow(k, i << 1) + T(1)) * ret).pre(i << 1) * (-ret + T(1)).inv(i << 1)).pre(i << 1) * T(k).inv(); // G_(i + 1)(x) = G_i(x) - (F(G_i(x)) - x) / F'(G_i(x)) // G_(i + 1)(x) = G_i(x) - (F(G_i(x)) - x) / ((d/dx)F(G_i(x)) / (d/dx)G_i(x)) ret = (ret - ((fg - P{0, 1}) * ret.diff()).pre(i << 1) * (fg.diff()).inv(i << 1)).pre(i << 1); } return ret.pre(deg); } */ // F(0) must be 1 P log(int deg = -1) const { assert((*this)[0] == T(1)); const int n = (int) this->size(); if(deg == -1) deg = n; return (this->diff() * this->inv(deg)).pre(deg - 1).integral(); } P sqrt(int deg = -1) const { const int n = (int) this->size(); if(deg == -1) deg = n; if((*this)[0] == T(0)) { for(int i = 1; i < n; i++) { if((*this)[i] != T(0)) { if(i & 1) return {}; if(deg - i / 2 <= 0) break; auto ret = (*this >> i).sqrt(deg - i / 2) << (i / 2); if(int(ret.size()) < deg) ret.resize(deg, T(0)); return ret; } } return P(deg, 0); } P ret({T(1)}); T inv2 = T(1) / T(2); for(int i = 1; i < deg; i <<= 1) { ret = (ret + pre(i << 1) * ret.inv(i << 1)) * inv2; } return ret.pre(deg); } // F(0) must be 0 P exp(int deg = -1) const { assert((*this)[0] == T(0)); const int n = (int) this->size(); if(deg == -1) deg = n; P ret({T(1)}); for(int i = 1; i < deg; i <<= 1) { ret = (ret * (pre(i << 1) + T(1) - ret.log(i << 1))).pre(i << 1); } return ret.pre(deg); } P pow(int k, int deg = -1) const { const int n = (int) this->size(); if(deg == -1) deg = n; for(int i = 0; i < n; i++) { if((*this)[i] != T(0)) { T rev = T(1) / (*this)[i]; P C(*this * rev); P D(n - i); for(int j = i; j < n; j++) D[j - i] = C[j]; D = (D.log(deg) * T(k)).exp() * (*this)[i].pow(k); P E(deg); if(i * k > deg) return E; auto S = i * k; for(int j = 0; j + S < deg && j < D.size(); j++) E[j + S] = D[j]; return E; } } return *this; } P taylor_shift(T x) const { const int n = (int) this->size(); P p(n), q(n); for(int i = 0; i < n; i++) p[i] = facts(i) * (*this)[i]; for(int i = 0; i < n; i++) q[i] = ifacts(n - 1 - i) * x.pow(n - 1 - i); p *= q; p = p >> (n - 1); for(int i = 0; i < n; i++) p[i] *= ifacts(i); return p; } T get(int idx){ assert(idx >= 0); if(idx < int(this->size())) return (*this)[idx]; else return T(0); } void set(int idx, T x){ assert(idx >= 0); if(idx < int(this->size())) (*this)[idx] = x; else{ this->resize(idx + 1); T(0); } return; } T eval(T x) const { T r = 0, w = 1; for(auto &v : *this) { r += w * v; w *= x; } return r; } }; template<typename T> T Bostan_Mori(FormalPowerSeries<T> P, FormalPowerSeries<T> Q, ll n){ assert(P.size() == Q.size()); if(n == 0) return P[0] / Q[0]; const int k = P.size(); FormalPowerSeries<T> R = Q; rep(i, k) if(i % 2 == 1) R[i] *= (T)-1; P *= R; Q *= R; FormalPowerSeries<T> U(k), V(k); if(n % 2 == 1) rep(i, k - 1) U[i] = P[2 * i + 1]; else rep(i, k) U[i] = P[2 * i]; rep(i, k) V[i] = Q[2 * i]; return Bostan_Mori(U, V, n / 2); } // C = A * B in the full_relaxed way // c_i = \sigma_{j = 0}^{i} a_{j} b_{i - j} // Postulate: at the point of i, all of the a_j, b_j (0 <= j <= i) are known // O(N(longN)^2) // 5e5 * 5e5 -> 3300 ms // https://judge.yosupo.jp/submission/167521 template<typename T> void convolution_online(FormalPowerSeries<T>& a, FormalPowerSeries<T>& b, FormalPowerSeries<T>& c, int idx){ assert(int(c.size()) >= int(a.size()) + int(b.size()) - 1); int two = 1; rep(_, 30){ if(idx == 0 and two >= 2) break; if(!(idx % two == max(0, two - 2))) break; { FormalPowerSeries<T> a1(two), b1(two), c1; rep(i, two){a1[i] = a[(two - 1) + i]; b1[i] = b[idx - (two - 1) + i];} c1 = a1 * b1; rep(i, two * 2 - 1) c[idx + i] += c1[i]; } if(idx == (two - 1) * 2) break; { FormalPowerSeries<T> a2(two), b2(two), c2; rep(i, two){a2[i] = a[idx - (two - 1) + i]; b2[i] = b[(two - 1) + i];} c2 = a2 * b2; rep(i, two * 2 - 1) c[idx + i] += c2[i]; } two *= 2; } } template<typename T> struct Merger{ int n; using P = FormalPowerSeries<T>; using Comp = std::function<bool(const P&, const P&)>; Comp comp = [](const P& a, const P& b){return a.size() > b.size();}; priority_queue<P, vector<P>, Comp> pq; Merger(int n = -1) : n(n), pq(comp){ pq.push(P{1}); } void add(P r){ pq.push(r); } P get(){ while(pq.size() > 1){ auto f = pq.top(); pq.pop(); auto g = pq.top(); pq.pop(); f *= g; if(n != -1) if(int(f.size()) > n) f.resize(n); pq.push(f); } P res = pq.top(); return res; } }; using FPS = FormalPowerSeries<mint>; int main(){ int n, K; cin >> n >> K; mint ans = 0; vector<int> a(n); cin >> a; map<int, int> frequency_p; for(int r = 1; r <= K; r++){ int p = gcd(K, r); frequency_p[p]++; } vector<FPS> f(K + 1); f[0] = {1}; for(int k = 1; k <= K; k++){ f[k] = f[k - 1]; f[k].push_back(ifacts(k)); } for(auto [p, c] : frequency_p){ int q = K / p; map<int, int> frequency_b; FPS g(p + 1, 0); g[0] = 1; rep(i, n){ g *= f[min(a[i] / q, K)]; g.resize(p + 1); } ans += g[p] * facts(p) * c; } cout << ans / K << "\n"; return 0; }