結果
問題 | No.2243 Coaching Schedule |
ユーザー | Jeroen Op de Beek |
提出日時 | 2023-03-10 22:56:26 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 658 ms / 4,000 ms |
コード長 | 5,254 bytes |
コンパイル時間 | 2,220 ms |
コンパイル使用メモリ | 215,472 KB |
実行使用メモリ | 28,460 KB |
最終ジャッジ日時 | 2024-09-18 05:05:23 |
合計ジャッジ時間 | 9,540 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 28 ms
21,120 KB |
testcase_01 | AC | 28 ms
21,072 KB |
testcase_02 | AC | 28 ms
20,992 KB |
testcase_03 | AC | 28 ms
21,068 KB |
testcase_04 | AC | 29 ms
21,068 KB |
testcase_05 | AC | 164 ms
28,460 KB |
testcase_06 | AC | 183 ms
26,732 KB |
testcase_07 | AC | 184 ms
26,740 KB |
testcase_08 | AC | 181 ms
26,728 KB |
testcase_09 | AC | 195 ms
24,924 KB |
testcase_10 | AC | 201 ms
24,916 KB |
testcase_11 | AC | 214 ms
24,924 KB |
testcase_12 | AC | 658 ms
23,816 KB |
testcase_13 | AC | 524 ms
23,804 KB |
testcase_14 | AC | 530 ms
23,804 KB |
testcase_15 | AC | 533 ms
23,808 KB |
testcase_16 | AC | 108 ms
23,644 KB |
testcase_17 | AC | 70 ms
22,476 KB |
testcase_18 | AC | 148 ms
25,868 KB |
testcase_19 | AC | 183 ms
24,752 KB |
testcase_20 | AC | 136 ms
22,528 KB |
testcase_21 | AC | 97 ms
23,680 KB |
testcase_22 | AC | 87 ms
23,424 KB |
testcase_23 | AC | 36 ms
21,580 KB |
testcase_24 | AC | 112 ms
23,736 KB |
testcase_25 | AC | 42 ms
21,776 KB |
testcase_26 | AC | 62 ms
22,476 KB |
testcase_27 | AC | 119 ms
23,688 KB |
testcase_28 | AC | 43 ms
21,712 KB |
testcase_29 | AC | 152 ms
24,772 KB |
testcase_30 | AC | 170 ms
26,240 KB |
testcase_31 | AC | 172 ms
26,448 KB |
testcase_32 | AC | 83 ms
23,120 KB |
testcase_33 | AC | 64 ms
22,784 KB |
testcase_34 | AC | 148 ms
25,504 KB |
testcase_35 | AC | 168 ms
25,352 KB |
testcase_36 | AC | 162 ms
26,132 KB |
ソースコード
#include "bits/stdc++.h" using namespace std; #define all(x) begin(x),end(x) template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; } #define debug(a) cerr << "(" << #a << ": " << a << ")\n"; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int,int> pi; const int mxN = 1<<19, oo = 1e9; const long long MD = 998244353; template<long long MOD=MD> struct mdint { int d=0; mdint () {d=0;} mdint (long long _d) : d(_d%MOD){ if(d<0) d+=MOD; }; friend mdint& operator+=(mdint& a, const mdint& o) { a.d+=o.d; if(a.d>=MOD) a.d-=MOD; return a; } friend mdint& operator-=(mdint& a, const mdint& o) { a.d-=o.d; if(a.d<0) a.d+=MOD; return a; } friend mdint& operator*=(mdint& a, const mdint& o) { return a = mdint((ll)a.d*o.d); } mdint operator*(const mdint& o) const { mdint res = *this; res*=o; return res; } mdint operator+(const mdint& o) const { mdint res = *this; res+=o; return res; } mdint operator-(const mdint& o) const { mdint res = *this; res-=o; return res; } mdint operator^(long long b) const { mdint tmp = 1; mdint power = *this; while(b) { if(b&1) { tmp = tmp*power; } power = power*power; b/=2; } return tmp; } friend mdint operator/=(mdint& a, const mdint& o) { a *= (o^(MOD-2)); return a; } mdint operator/(const mdint& o) { mdint res = *this; res/=o; return res; } bool operator==(const mdint& o) { return d==o.d;} bool operator!=(const mdint& o) { return d!=o.d;} friend istream& operator>>(istream& c, mdint& a) {return c >> a.d;} friend ostream& operator<<(ostream& c, const mdint& a) {return c << a.d;} }; using mint = mdint<MD>; typedef mint cd; void revperm(cd* in, int n) { for(int i=0,j=0;i<n;++i) { if(i<j) swap(in[i],in[j]); for(int k = n >> 1; (j ^= k) < k; k >>= 1); } } cd w[mxN+1]; // stores w^j for each j in [0,n-1] void precomp() { w[0] = 1; int pw = (MD-1)/mxN; w[1] = mint(3)^pw; for(int i= 2;i<=mxN;++i) { w[i] = w[i-1]*w[1]; } } void fft(cd* in, int n, bool reverse=false) { int lg = __lg(n); assert(1<<lg == n); int stride = mxN/n; revperm(in,n); for(int s=1;s<=lg;++s) { int pw = 1<<s; int mstride = stride*(n>>s); for(int j=0;j<n;j+=pw) { // do FFT merging on out array cd* even = in+j, *odd = in+j+pw/2; for(int i=0;i<pw/2;++i) { cd& power = w[reverse?mxN-mstride*i:mstride*i]; auto tmp = power*odd[i]; odd[i] = even[i] - tmp; even[i] = even[i] + tmp; } } } if(reverse) { mint fac = mint(1)/n; for(int i=0;i<n;++i) in[i]=in[i]*fac; } } vector<cd> polymul(vector<cd>& a, vector<cd>& b) { int n = a.size(), m = b.size(), ptwo = 1; while(ptwo<(n+m)) ptwo*=2; a.resize(ptwo), b.resize(ptwo); fft(a.data(),ptwo); fft(b.data(),ptwo); for(int i=0;i<ptwo;++i) a[i] = a[i]*b[i]; fft(a.data(),ptwo,true); a.resize(n+m-1); return a; } const int mxF = 2e6+2; mint fact[mxF], ifact[mxF]; cd ncr(int a, int b) { if(b>a or a<0 or b<0) return 0; return ifact[b]*ifact[a-b]; } void precomp2() { fact[0]=1; for(int i=1;i<mxF;++i) { fact[i]=fact[i-1]*i; } ifact[mxF-1] = mint(1)/fact[mxF-1]; for(int i=mxF-2;i>=0;--i) { ifact[i]=ifact[i+1]*(i+1); } } int main() { precomp(); precomp2(); // ok need to choose subsets but only of unique // first choose number of days? // then choose how to do it? // you choose a subset of exactly so many // but empty is not allowed. // do it just with empties. // then choose which days to empty int n,m; cin >> m >> n; map<int,int> cnt; for(int i=0;i<n;++i) { int a; cin >> a; cnt[a]++; } // only sqrt items. // have to subtract those with ncr factors in front. // and one of those is just binomial coefs multiplied. vector<mint> aa(n+1),bb(n+1); map<int,int> cntcnt; for(auto [j,c] : cnt) cntcnt[c]++; for(int i=1;i<=n;++i) { aa[i]=fact[i]^cnt.size(); for(auto [j,c] : cntcnt) { if(aa[i]==0) break; aa[i]*=ncr(i,j)^c; } aa[i]*=ifact[i]; } mint pw=1; for(int i=0;i<=n;++i) { // /i! bb[i] = ifact[i]*pw; pw*=MD-1; } auto cc = polymul(aa,bb); mint ans=0; for(int i=1;i<=n;++i) { cc[i]*=fact[i]; ans+=cc[i]; } for(auto [j,c] : cnt) ans*=fact[c]; cout << ans << '\n'; }