結果
問題 | No.2959 Dolls' Tea Party |
ユーザー | shobonvip |
提出日時 | 2024-11-10 23:12:16 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,099 ms / 3,000 ms |
コード長 | 3,872 bytes |
コンパイル時間 | 5,655 ms |
コンパイル使用メモリ | 276,696 KB |
実行使用メモリ | 18,944 KB |
最終ジャッジ日時 | 2024-11-10 23:13:00 |
合計ジャッジ時間 | 37,172 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 14 ms
11,136 KB |
testcase_01 | AC | 14 ms
11,136 KB |
testcase_02 | AC | 14 ms
11,264 KB |
testcase_03 | AC | 14 ms
11,136 KB |
testcase_04 | AC | 14 ms
11,136 KB |
testcase_05 | AC | 18 ms
11,264 KB |
testcase_06 | AC | 1,048 ms
18,560 KB |
testcase_07 | AC | 1,072 ms
18,944 KB |
testcase_08 | AC | 1,075 ms
18,688 KB |
testcase_09 | AC | 1,092 ms
18,560 KB |
testcase_10 | AC | 1,064 ms
18,560 KB |
testcase_11 | AC | 1,096 ms
18,688 KB |
testcase_12 | AC | 1,081 ms
18,688 KB |
testcase_13 | AC | 1,068 ms
18,560 KB |
testcase_14 | AC | 1,099 ms
18,560 KB |
testcase_15 | AC | 1,061 ms
18,944 KB |
testcase_16 | AC | 1,092 ms
18,560 KB |
testcase_17 | AC | 1,076 ms
18,560 KB |
testcase_18 | AC | 1,062 ms
18,688 KB |
testcase_19 | AC | 1,061 ms
18,560 KB |
testcase_20 | AC | 1,058 ms
18,688 KB |
testcase_21 | AC | 1,093 ms
18,944 KB |
testcase_22 | AC | 1,044 ms
18,816 KB |
testcase_23 | AC | 1,071 ms
18,944 KB |
testcase_24 | AC | 15 ms
11,264 KB |
testcase_25 | AC | 14 ms
11,136 KB |
testcase_26 | AC | 14 ms
11,136 KB |
testcase_27 | AC | 1,032 ms
18,048 KB |
testcase_28 | AC | 1,025 ms
17,920 KB |
testcase_29 | AC | 1,049 ms
18,816 KB |
testcase_30 | AC | 994 ms
18,560 KB |
testcase_31 | AC | 1,020 ms
18,688 KB |
testcase_32 | AC | 977 ms
18,048 KB |
testcase_33 | AC | 1,055 ms
18,816 KB |
testcase_34 | AC | 1,051 ms
18,688 KB |
testcase_35 | AC | 1,020 ms
18,944 KB |
testcase_36 | AC | 981 ms
18,304 KB |
ソースコード
/** author: shobonvip created: 2024.11.10 23:02:46 **/ #include<bits/stdc++.h> using namespace std; //* ATCODER #include<atcoder/all> using namespace atcoder; typedef modint998244353 mint; //*/ /* BOOST MULTIPRECISION #include<boost/multiprecision/cpp_int.hpp> using namespace boost::multiprecision; //*/ typedef long long ll; #define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--) template <typename T> bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template <typename T> bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } template <typename T> T max(vector<T> &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]); return ret; } template <typename T> T min(vector<T> &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]); return ret; } template <typename T> T sum(vector<T> &a){ T ret = 0; for (int i=0; i<(int)a.size(); i++) ret += a[i]; return ret; } //defmodfact const int COMinitMAX = 992844; mint fact[COMinitMAX+1], factinv[COMinitMAX+1]; void modfact(){ fact[0] = 1; for (int i=1; i<=COMinitMAX; i++){ fact[i] = fact[i-1] * i; } factinv[COMinitMAX] = fact[COMinitMAX].inv(); for (int i=COMinitMAX-1; i>=0; i--){ factinv[i] = factinv[i+1] * (i+1); } } mint binom(int a, int b){ if (a<b || b<0) return mint(0); return fact[a]*factinv[b]*factinv[a-b]; } //-------- // Inv of Polynomial // O(N log N) // T should be modint template<typename T> std::vector<T> poly_inv(std::vector<T> &a, int M = -314159265){ if (M == -314159265) M = (int)a.size(); else if (M <= 0) return {}; int n = a.size(); T r = a[0].pow(T::mod()-2); int m = 1; std::vector<T> res = {r}; while (m < M){ std::vector<T> f = a; f.resize(std::min(n, 2*m)); std::vector<T> h = atcoder::convolution(f, res); for (int i=0; i<std::min(2*m, (int)h.size()); i++){ h[i] = -h[i]; } h[0] += 2; h.resize(2*m); h = atcoder::convolution(h, res); h.resize(2*m); swap(res, h); m <<= 1; } res.resize(M); return res; } vector<mint> poly_log(vector<mint> &a, int M = -314159265){ if (M == -314159265) M = (int)a.size(); else if (M <= 0) return {}; int n = a.size(); if (n == 1) return vector<mint>(M, 0); vector<mint> b(n-1); for (int i=0; i<n-1; i++){ b[i] = a[i+1] * (i+1); } vector<mint> t = convolution<mint>(b, poly_inv(a, M)); vector<mint> ret(M); for (int i=0; i<M-1; i++){ ret[i+1] = t[i] * factinv[i+1] * fact[i]; } return ret; } vector<mint> poly_exp(vector<mint> &a, int M = -314159265){ if (M == -314159265) M = (int)a.size(); else if (M <= 0) return {}; int n = a.size(); int m = 1; vector<mint> res = {1}; while (m < M){ vector<mint> f(2*m); for (int i=0; i<min(n, 2*m); i++) f[i] = a[i]; vector<mint> v = poly_log(res, 2*m); vector<mint> w(2*m); for (int i=0; i<2*m; i++) w[i] = f[i] - v[i]; w[0] += 1; vector<mint> g = convolution<mint>(res, w); res.insert(res.end(), g.begin()+m, g.begin()+2*m); m <<= 1; } res.resize(M); return res; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); modfact(); int n, k; cin >> n >> k; vector<int> a(n); rep(i,0,n) cin >> a[i]; vector<vector<mint>> logs(k+1, vector<mint>(k+1)); rep(i,0,k+1){ rep(j,0,i+1){ logs[i][j] = factinv[j]; } logs[i] = poly_log(logs[i]); } vector<mint> tar(k+1); rep(g,1,k+1){ if (k % g == 0) { int l = k / g; vector<mint> val(g + 1); rep(i,0,n) { val[min(a[i] / l, g)] += 1; } vector<mint> f(g + 1); rep(i,0,g+1) { rep(j,0,g+1){ f[j] += val[i] * logs[i][j]; } } tar[g] = poly_exp(f)[g] * fact[g]; } } mint ans = 0; rep(i,0,k){ int g = __gcd(i, k); ans += tar[g]; } ans /= k; cout << ans.val() << '\n'; }