結果
問題 | No.1621 Sequence Inversions |
ユーザー | 👑 rin204 |
提出日時 | 2022-04-15 15:08:33 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 201 ms / 3,000 ms |
コード長 | 3,532 bytes |
コンパイル時間 | 463 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 81,964 KB |
最終ジャッジ日時 | 2024-06-07 00:56:40 |
合計ジャッジ時間 | 4,093 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
54,400 KB |
testcase_01 | AC | 46 ms
54,272 KB |
testcase_02 | AC | 76 ms
70,272 KB |
testcase_03 | AC | 45 ms
54,912 KB |
testcase_04 | AC | 46 ms
54,656 KB |
testcase_05 | AC | 45 ms
54,400 KB |
testcase_06 | AC | 59 ms
64,256 KB |
testcase_07 | AC | 76 ms
72,320 KB |
testcase_08 | AC | 201 ms
81,964 KB |
testcase_09 | AC | 163 ms
79,872 KB |
testcase_10 | AC | 163 ms
79,616 KB |
testcase_11 | AC | 198 ms
81,836 KB |
testcase_12 | AC | 148 ms
78,276 KB |
testcase_13 | AC | 124 ms
77,696 KB |
testcase_14 | AC | 116 ms
77,568 KB |
testcase_15 | AC | 115 ms
77,184 KB |
testcase_16 | AC | 116 ms
76,928 KB |
testcase_17 | AC | 122 ms
77,056 KB |
testcase_18 | AC | 115 ms
77,184 KB |
testcase_19 | AC | 81 ms
73,088 KB |
testcase_20 | AC | 105 ms
76,800 KB |
testcase_21 | AC | 122 ms
77,312 KB |
testcase_22 | AC | 119 ms
77,184 KB |
testcase_23 | AC | 125 ms
77,056 KB |
testcase_24 | AC | 46 ms
54,784 KB |
testcase_25 | AC | 47 ms
55,296 KB |
testcase_26 | AC | 44 ms
54,016 KB |
testcase_27 | AC | 45 ms
54,656 KB |
testcase_28 | AC | 44 ms
54,144 KB |
ソースコード
from collections import deque MOD = 998244353 class FFT: def __init__(self, MOD=998244353): FFT.MOD = MOD g = self.primitive_root_constexpr() ig = pow(g, FFT.MOD - 2, FFT.MOD) FFT.W = [pow(g, (FFT.MOD - 1) >> i, FFT.MOD) for i in range(30)] FFT.iW = [pow(ig, (FFT.MOD - 1) >> i, FFT.MOD) for i in range(30)] def primitive_root_constexpr(self): if FFT.MOD == 998244353: return 3 elif FFT.MOD == 200003: return 2 elif FFT.MOD == 167772161: return 3 elif FFT.MOD == 469762049: return 3 elif FFT.MOD == 754974721: return 11 divs = [0] * 20 divs[0] = 2 cnt = 1 x = (FFT.MOD - 1) // 2 while x % 2 == 0: x //= 2 i = 3 while i * i <= x: if x % i == 0: divs[cnt] = i cnt += 1 while x % i == 0: x //= i i += 2 if x > 1: divs[cnt] = x cnt += 1 g = 2 while 1: ok = True for i in range(cnt): if pow(g, (FFT.MOD - 1) // divs[i], FFT.MOD) == 1: ok = False break if ok: return g g += 1 def fft(self, k, f): for l in range(k, 0, -1): d = 1 << l - 1 U = [1] for i in range(d): U.append(U[-1] * FFT.W[l] % FFT.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]) % FFT.MOD, U[j] * (f[s] - f[s + d]) % FFT.MOD def ifft(self, 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]) % FFT.MOD, (f[j] - f[j + d]) % FFT.MOD u = u * FFT.iW[l] % FFT.MOD def convolve(self, A, B): n0 = len(A) + len(B) - 1 k = (n0).bit_length() n = 1 << k A += [0] * (n - len(A)) B += [0] * (n - len(B)) self.fft(k, A) self.fft(k, B) A = [a * b % FFT.MOD for a, b in zip(A, B)] self.ifft(k, A) inv = pow(n, FFT.MOD - 2, FFT.MOD) A = [a * inv % FFT.MOD for a in A] del A[n0:] return A n, K = map(int, input().split()) A = list(map(int, input().split())) cnt = {} for a in A: cnt[a] = cnt.get(a, 0) + 1 queue = deque() tot = 0 for k in sorted(set(A)): v = cnt[k] dp = [[0] * (tot + 1)] dp[0][0] = 1 l = 1 for _ in range(v): ndp = [[0] * (tot + 1) for _ in range(l + tot)] for i in range(l): for j in range(tot + 1): ndp[i + j][j] += dp[i][j] ndp[i + j][j] %= MOD l += tot for i in range(1, l): for j in range(1, tot + 1): ndp[i][j] += ndp[i - 1][j - 1] ndp[i][j] %= MOD dp = ndp tot += v poly = [sum(ndp[i]) for i in range(l)] del poly[K+1:] queue.append(poly) fft = FFT() while len(queue) > 1: A = queue.popleft() B = queue.popleft() C = fft.convolve(A, B) del C[K+1:] queue.append(C) A = queue[0] if len(A) <= K: print(0) else: print(A[K])