結果
問題 | No.2243 Coaching Schedule |
ユーザー | shobonvip |
提出日時 | 2023-03-10 00:38:47 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,775 ms / 4,000 ms |
コード長 | 2,169 bytes |
コンパイル時間 | 139 ms |
コンパイル使用メモリ | 82,024 KB |
実行使用メモリ | 125,952 KB |
最終ジャッジ日時 | 2024-09-18 03:07:47 |
合計ジャッジ時間 | 17,216 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 68 ms
74,752 KB |
testcase_01 | AC | 62 ms
74,880 KB |
testcase_02 | AC | 62 ms
74,496 KB |
testcase_03 | AC | 61 ms
74,752 KB |
testcase_04 | AC | 64 ms
76,032 KB |
testcase_05 | AC | 273 ms
125,696 KB |
testcase_06 | AC | 435 ms
117,120 KB |
testcase_07 | AC | 448 ms
118,380 KB |
testcase_08 | AC | 431 ms
118,424 KB |
testcase_09 | AC | 538 ms
117,120 KB |
testcase_10 | AC | 552 ms
118,344 KB |
testcase_11 | AC | 543 ms
118,308 KB |
testcase_12 | AC | 1,775 ms
116,844 KB |
testcase_13 | AC | 1,611 ms
117,504 KB |
testcase_14 | AC | 1,613 ms
117,504 KB |
testcase_15 | AC | 1,581 ms
116,992 KB |
testcase_16 | AC | 224 ms
125,952 KB |
testcase_17 | AC | 174 ms
99,068 KB |
testcase_18 | AC | 338 ms
113,452 KB |
testcase_19 | AC | 485 ms
114,304 KB |
testcase_20 | AC | 390 ms
108,672 KB |
testcase_21 | AC | 235 ms
107,144 KB |
testcase_22 | AC | 216 ms
106,536 KB |
testcase_23 | AC | 108 ms
93,400 KB |
testcase_24 | AC | 277 ms
109,440 KB |
testcase_25 | AC | 117 ms
93,952 KB |
testcase_26 | AC | 157 ms
97,920 KB |
testcase_27 | AC | 290 ms
109,568 KB |
testcase_28 | AC | 120 ms
93,824 KB |
testcase_29 | AC | 375 ms
119,296 KB |
testcase_30 | AC | 395 ms
114,688 KB |
testcase_31 | AC | 389 ms
117,112 KB |
testcase_32 | AC | 204 ms
105,536 KB |
testcase_33 | AC | 159 ms
99,072 KB |
testcase_34 | AC | 345 ms
113,524 KB |
testcase_35 | AC | 397 ms
113,920 KB |
testcase_36 | AC | 379 ms
115,456 KB |
ソースコード
# FFT が遅い mod = 998244353 g = 3 ginv = 332748118 W = [pow(g, (mod-1)>>i, mod) for i in range(24)] Winv = [pow(ginv, (mod-1)>>i, mod) for i in range(24)] def fft(k, f): for l in range(k, 0, -1): d = 1<<l-1 U = [1] for i in range(d): U.append(U[-1]*W[l]%mod) for i in range(1<<k-l): for j in range(d): s = i*2*d+j f[s], f[s+d] = (f[s]+f[s+d])%mod, U[j]*(f[s]-f[s+d])%mod def fftinv(k, f): for l in range(1, k+1): d = 1<<l-1 for i in range(1<<k-l): u = 1 for j in range(i*2*d, (i*2+1)*d): f[j+d] *= u f[j], f[j+d] = (f[j]+f[j+d])%mod, (f[j]-f[j+d])%mod u *= Winv[l] u %= mod def convolution(a, b): le = len(a)+len(b)-1 k = le.bit_length() n = 1<<k a = a+[0]*(n-len(a)) b = b+[0]*(n-len(b)) fft(k, a) fft(k, b) for i in range(n): a[i] *= b[i] a[i] %= mod fftinv(k, a) ninv = pow(n, mod-2, mod) for i in range(le): a[i] *= ninv a[i] %= mod return a[:le] mod = 998244353 N = 10**6 + 5 fact = [1]*(N+1) factinv = [1]*(N+1) for i in range(2, N+1): fact[i] = fact[i-1] * i % mod factinv[-1] = pow(fact[-1], mod-2, mod) for i in range(N-1, 1, -1): factinv[i] = factinv[i+1] * (i+1) % mod def cmb(a, b): if (a < b) or (b < 0): return 0 return fact[a] * factinv[b] % mod * factinv[a-b] % mod # ここから本編. m,n = map(int,input().split()) a = list(map(int,input().split())) # 頻度ごとに集計しています O(N+M) c = [0] * m for i in range(n): c[a[i]-1] += 1 cl = [0] * (n+1) for i in range(m): cl[c[i]] += 1 cv = [] cmax = 0 for i in range(n+1): if cl[i] > 0: cv.append((i, cl[i])) cmax = max(cmax, i) # 想定解通りにやります O(N^1.5 log N) ? わからんぬ d = [1] * (n+1) for i in range(n+1): if cmax > i: d[i] = 0 continue for j, cnt in cv: d[i] *= pow(fact[i] * factinv[i-j] % mod, cnt, mod) d[i] %= mod # またまたFFTによって練習の日を固定したときの数え上げを計算します O(N log N) f = [d[i] * factinv[i] % mod for i in range(n + 1)] g = [(-1) ** (i % 2) * factinv[i] % mod for i in range(n + 1)] fg = convolution(f, g) ans = 0 for i in range(n + 1): ans += fact[i] * fg[i] % mod print(ans % mod)