結果
問題 | No.2959 Dolls' Tea Party |
ユーザー | KumaTachiRen |
提出日時 | 2024-11-08 22:34:45 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 918 ms / 3,000 ms |
コード長 | 12,468 bytes |
コンパイル時間 | 7,797 ms |
コンパイル使用メモリ | 346,204 KB |
実行使用メモリ | 13,568 KB |
最終ジャッジ日時 | 2024-11-08 22:35:16 |
合計ジャッジ時間 | 25,335 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
5,248 KB |
testcase_01 | AC | 4 ms
5,248 KB |
testcase_02 | AC | 4 ms
5,248 KB |
testcase_03 | AC | 4 ms
5,248 KB |
testcase_04 | AC | 4 ms
5,248 KB |
testcase_05 | AC | 4 ms
5,248 KB |
testcase_06 | AC | 44 ms
5,888 KB |
testcase_07 | AC | 48 ms
5,760 KB |
testcase_08 | AC | 45 ms
5,888 KB |
testcase_09 | AC | 857 ms
12,672 KB |
testcase_10 | AC | 887 ms
12,672 KB |
testcase_11 | AC | 867 ms
12,672 KB |
testcase_12 | AC | 872 ms
12,800 KB |
testcase_13 | AC | 881 ms
12,672 KB |
testcase_14 | AC | 47 ms
5,760 KB |
testcase_15 | AC | 47 ms
5,888 KB |
testcase_16 | AC | 890 ms
12,800 KB |
testcase_17 | AC | 867 ms
12,672 KB |
testcase_18 | AC | 865 ms
12,800 KB |
testcase_19 | AC | 888 ms
12,800 KB |
testcase_20 | AC | 868 ms
12,672 KB |
testcase_21 | AC | 918 ms
13,312 KB |
testcase_22 | AC | 898 ms
13,184 KB |
testcase_23 | AC | 900 ms
13,184 KB |
testcase_24 | AC | 4 ms
5,248 KB |
testcase_25 | AC | 4 ms
5,248 KB |
testcase_26 | AC | 4 ms
5,248 KB |
testcase_27 | AC | 10 ms
5,248 KB |
testcase_28 | AC | 9 ms
5,248 KB |
testcase_29 | AC | 23 ms
5,760 KB |
testcase_30 | AC | 22 ms
5,888 KB |
testcase_31 | AC | 24 ms
5,888 KB |
testcase_32 | AC | 828 ms
12,800 KB |
testcase_33 | AC | 872 ms
13,184 KB |
testcase_34 | AC | 870 ms
12,928 KB |
testcase_35 | AC | 867 ms
13,568 KB |
testcase_36 | AC | 812 ms
12,800 KB |
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/x86_64-pc-linux-gnu/bits/c++allocator.h:33, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/allocator.h:46, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/string:41, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/locale_classes.h:40, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/ios_base.h:41, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ios:42, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/istream:38, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/sstream:38, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/complex:45, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ccomplex:39, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/x86_64-pc-linux-gnu/bits/stdc++.h:54, from main.cpp:3: In member function 'void std::__new_allocator<_Tp>::deallocate(_Tp*, size_type) [with _Tp = atcoder::static_modint<998244353>]', inlined from 'constexpr void std::allocator< <template-parameter-1-1> >::deallocate(_Tp*, std::size_t) [with _Tp = atcoder::static_modint<998244353>]' at /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/allocator.h:200:35, inlined from 'static constexpr void std::allocator_traits<std::allocator<_CharT> >::deallocate(allocator_type&, pointer, size_type) [with _Tp = atcoder::static_modint<998244353>]' at /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/alloc_traits.h:496:23, inlined from 'constexpr void std::_Vector_base<_Tp, _Alloc>::_M_deallocate(pointer, std::size_t) [with _Tp = atcoder::static_modint<998244353>; _Alloc = std:
ソースコード
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #if __has_include(<atcoder/all>) #include <atcoder/all> using namespace atcoder; using mint = modint998244353; using vm = vector<mint>; using vvm = vector<vm>; inline ostream &operator<<(ostream &os, const mint x) { return os << x.val(); }; inline istream &operator>>(istream &is, mint &x) { long long v; is >> v; x = v; return is; }; #endif struct Fast { Fast() { std::cin.tie(nullptr); ios::sync_with_stdio(false); cout << setprecision(10); } } fast; #define all(a) (a).begin(), (a).end() #define contains(a, x) ((a).find(x) != (a).end()) #define rep(i, a, b) for (int i = (a); i < (int)(b); i++) #define rrep(i, a, b) for (int i = (int)(b) - 1; i >= (a); i--) #define YN(b) cout << ((b) ? "YES" : "NO") << "\n"; #define Yn(b) cout << ((b) ? "Yes" : "No") << "\n"; #define yn(b) cout << ((b) ? "yes" : "no") << "\n"; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } using ll = long long; using vb = vector<bool>; using vvb = vector<vb>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> &p) { os << "(" << p.first << "," << p.second << ")"; return os; } template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) { for (int i = 0; i < (int)vec.size(); i++) { os << vec[i] << (i + 1 == (int)vec.size() ? "" : " "); } return os; } template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (int i = 0; i < (int)vec.size(); i++) is >> vec[i]; return is; } ll floor(ll a, ll b) { return a >= 0 ? a / b : (a + 1) / b - 1; } ll ceil(ll a, ll b) { return a > 0 ? (a - 1) / b + 1 : a / b; } template <typename mint> struct FormalPowerSeries : vector<mint> { using vector<mint>::vector; using FPS = FormalPowerSeries; FPS &operator+=(const FPS &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; } FPS &operator+=(const mint &r) { if (this->empty()) this->resize(1); (*this)[0] += r; return *this; } FPS &operator-=(const FPS &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; } FPS &operator-=(const mint &r) { if (this->empty()) this->resize(1); (*this)[0] -= r; return *this; } FPS &operator*=(const mint &v) { for (int k = 0; k < (int)this->size(); k++) (*this)[k] *= v; return *this; } FPS &operator*=(const FPS &r) { auto c = atcoder::convolution<mint>((*this), r); this->resize(c.size()); for (int i = 0; i < (int)c.size(); i++) (*this)[i] = c[i]; return *this; } FPS &operator/=(const FPS &r) { if (this->size() < r.size()) { this->clear(); return *this; } int n = this->size() - r.size() + 1; if ((int)r.size() <= 64) { FPS f(*this), g(r); g.shrink(); mint coeff = g.at(g.size() - 1).inv(); for (auto &x : g) x *= coeff; int deg = (int)f.size() - (int)g.size() + 1; int gs = g.size(); FPS quo(deg); for (int i = deg - 1; i >= 0; i--) { quo[i] = f[i + gs - 1]; for (int j = 0; j < gs; j++) f[i + j] -= quo[i] * g[j]; } *this = quo * coeff; this->resize(n, mint(0)); return *this; } return *this = ((*this).rev().pre(n) * r.rev().inv(n)).pre(n).rev(); } FPS &operator%=(const FPS &r) { *this -= *this / r * r; shrink(); return *this; } FPS operator+(const FPS &r) const { return FPS(*this) += r; } FPS operator+(const mint &v) const { return FPS(*this) += v; } FPS operator-(const FPS &r) const { return FPS(*this) -= r; } FPS operator-(const mint &v) const { return FPS(*this) -= v; } FPS operator*(const FPS &r) const { return FPS(*this) *= r; } FPS operator*(const mint &v) const { return FPS(*this) *= v; } FPS operator/(const FPS &r) const { return FPS(*this) /= r; } FPS operator%(const FPS &r) const { return FPS(*this) %= r; } FPS operator-() const { FPS ret(this->size()); for (int i = 0; i < (int)this->size(); i++) ret[i] = -(*this)[i]; return ret; } void shrink() { while (this->size() && this->back() == mint(0)) this->pop_back(); } FPS rev() const { FPS ret(*this); reverse(begin(ret), end(ret)); return ret; } FPS dot(FPS r) const { FPS ret(min(this->size(), r.size())); for (int i = 0; i < (int)ret.size(); i++) ret[i] = (*this)[i] * r[i]; return ret; } FPS pre(int sz) const { return FPS(begin(*this), begin(*this) + min((int)this->size(), sz)); } FPS operator>>=(int sz) { assert(sz >= 0); if ((int)this->size() <= sz) return {}; this->erase(this->begin(), this->begin() + sz); return *this; } FPS operator>>(int sz) const { if ((int)this->size() <= sz) return {}; FPS ret(*this); ret.erase(ret.begin(), ret.begin() + sz); return ret; } FPS operator<<=(int sz) { assert(sz >= 0); this->insert(this->begin(), sz, mint(0)); return *this; } FPS operator<<(int sz) const { FPS ret(*this); ret.insert(ret.begin(), sz, mint(0)); return ret; } FPS diff() const { const int n = (int)this->size(); FPS ret(max(0, n - 1)); mint one(1), coeff(1); for (int i = 1; i < n; i++) { ret[i - 1] = (*this)[i] * coeff; coeff += one; } return ret; } FPS integral() const { const int n = (int)this->size(); FPS ret(n + 1); ret[0] = mint(0); if (n > 0) ret[1] = mint(1); auto mod = mint::mod(); for (int i = 2; i <= n; i++) ret[i] = (-ret[mod % i]) * (mod / i); for (int i = 0; i < n; i++) ret[i + 1] *= (*this)[i]; return ret; } mint eval(mint x) const { mint r = 0, w = 1; for (auto &v : *this) r += w * v, w *= x; return r; } FPS log(int deg = -1) const { assert((*this)[0] == mint(1)); if (deg == -1) deg = (int)this->size(); return (this->diff() * this->inv(deg)).pre(deg - 1).integral(); } FPS pow(int64_t k, int deg = -1) const { const int n = (int)this->size(); if (deg == -1) deg = n; if (k == 0) { FPS ret(deg); if (deg) ret[0] = 1; return ret; } for (int i = 0; i < n; i++) { if ((*this)[i] != mint(0)) { mint rev = mint(1) / (*this)[i]; FPS ret = (((*this * rev) >> i).log(deg) * k).exp(deg); ret *= (*this)[i].pow(k); ret = (ret << (i * k)).pre(deg); if ((int)ret.size() < deg) ret.resize(deg, mint(0)); return ret; } if (__int128_t(i + 1) * k >= deg) return FPS(deg, mint(0)); } return FPS(deg, mint(0)); } FPS inv(int deg = -1) const { assert((*this)[0] != mint(0)); if (deg == -1) deg = (*this).size(); FPS ret{mint(1) / (*this)[0]}; for (int i = 1; i < deg; i <<= 1) ret = (ret + ret - ret * ret * (*this).pre(i << 1)).pre(i << 1); return ret.pre(deg); } FPS exp(int deg = -1) const { assert((*this)[0] == mint(0)); if (deg == -1) deg = (*this).size(); FPS ret{mint(1)}; for (int i = 1; i < deg; i <<= 1) ret = (ret * ((*this).pre(i << 1) - ret.log(i << 1) + 1)).pre(i << 1); return ret.pre(deg); } }; using fps = FormalPowerSeries<mint>; template <typename mint> struct factorial { vector<mint> f, g, h; factorial(int MAX = 0) { f.resize(1, mint{1}); g.resize(1, mint{1}); h.resize(1, mint{1}); if (MAX > 0) extend(MAX + 1); } void extend(int m = -1) { int n = f.size(); if (m == -1) m = n * 2; if (n >= m) return; f.resize(m); g.resize(m); h.resize(m); for (int i = n; i < m; i++) f[i] = f[i - 1] * mint(i); g[m - 1] = f[m - 1].inv(); h[m - 1] = g[m - 1] * f[m - 2]; for (int i = m - 2; i >= n; i--) { g[i] = g[i + 1] * mint(i + 1); h[i] = g[i] * f[i - 1]; } } mint fact(int i) { if (i < 0) return mint(0); while (i >= (int)f.size()) extend(); return f[i]; } mint fact_inv(int i) { if (i < 0) return mint(0); while (i >= (int)g.size()) extend(); return g[i]; } mint inv(int i) { if (i < 0) return -inv(-i); while (i >= (int)h.size()) extend(); return h[i]; } mint binom(int n, int r) { if (n < 0 || n < r || r < 0) return mint(0); return fact(n) * fact_inv(n - r) * fact_inv(r); } mint multinom(const vector<int> &r) { int n = 0; for (auto &x : r) { if (x < 0) return mint(0); n += x; } mint res = fact(n); for (auto &x : r) res *= fact_inv(x); return res; } mint binom_naive(int n, int r) { if (n < 0 || n < r || r < 0) return mint(0); mint ret = mint(1); r = min(r, n - r); for (int i = 1; i <= r; ++i) ret *= inv(i) * (n--); return ret; } mint P(int n, int r) { if (n < 0 || n < r || r < 0) return mint(0); return fact(n) * fact_inv(n - r); } mint H(int n, int r) { if (n < 0 || r < 0) return mint(0); return r == 0 ? 1 : binom(n + r - 1, r); } }; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } void solve() { int n, k; cin >> n >> k; vi a(n); rep(i, 0, n) cin >> a[i]; vi b(k + 1, 0); for (auto v : a) b[min(v, k)]++; vi c(k + 1, 0); rep(i, 0, k) c[gcd(i, k)]++; factorial<mint> fact(100000); map<int, vm> log_memo; mint ans = 0; for (int w = k; w > 0; w--) { if (c[w] == 0) continue; int d = k / w; int s = 0; vi cnt(w + 1, 0); for (int i = 0; i <= k; i++) { if (b[i] == 0) continue; int m = min(w, i / d); s += m * b[i]; cnt[m] += b[i]; } if (s < w) continue; fps f(w + 1, 0); for (int i = 1; i <= w; i++) { if (cnt[i] == 0) continue; if (!contains(log_memo, i)) { fps g(i + 1, 0); rep(j, 0, i + 1) g[j] = fact.fact_inv(j); log_memo[i] = g.log(w + 1); } { auto g = log_memo[i]; for (int j = 0; j <= w; j++) f[j] += g[j] * cnt[i]; } } f = f.exp(); ans += f[w] * fact.fact(w) * c[w]; } ans *= fact.inv(k); cout << ans.val() << "\n"; } int main() { int t = 1; // cin >> t; while (t--) solve(); }