結果
問題 | No.1387 Mitarushi's Remodeling |
ユーザー | Mitarushi |
提出日時 | 2021-01-20 22:55:30 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 836 ms / 2,000 ms |
コード長 | 1,903 bytes |
コンパイル時間 | 140 ms |
コンパイル使用メモリ | 81,992 KB |
実行使用メモリ | 206,192 KB |
最終ジャッジ日時 | 2024-06-29 23:14:57 |
合計ジャッジ時間 | 49,239 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 87 ms
98,304 KB |
testcase_01 | AC | 81 ms
98,296 KB |
testcase_02 | AC | 82 ms
98,432 KB |
testcase_03 | AC | 81 ms
98,432 KB |
testcase_04 | AC | 84 ms
98,704 KB |
testcase_05 | AC | 81 ms
98,704 KB |
testcase_06 | AC | 87 ms
98,432 KB |
testcase_07 | AC | 84 ms
98,328 KB |
testcase_08 | AC | 126 ms
100,704 KB |
testcase_09 | AC | 120 ms
100,824 KB |
testcase_10 | AC | 125 ms
100,992 KB |
testcase_11 | AC | 122 ms
100,980 KB |
testcase_12 | AC | 119 ms
100,592 KB |
testcase_13 | AC | 123 ms
100,608 KB |
testcase_14 | AC | 793 ms
202,412 KB |
testcase_15 | AC | 770 ms
201,936 KB |
testcase_16 | AC | 786 ms
202,052 KB |
testcase_17 | AC | 748 ms
202,068 KB |
testcase_18 | AC | 760 ms
202,144 KB |
testcase_19 | AC | 780 ms
202,068 KB |
testcase_20 | AC | 777 ms
202,532 KB |
testcase_21 | AC | 771 ms
202,152 KB |
testcase_22 | AC | 774 ms
202,148 KB |
testcase_23 | AC | 764 ms
202,064 KB |
testcase_24 | AC | 773 ms
201,896 KB |
testcase_25 | AC | 792 ms
202,192 KB |
testcase_26 | AC | 782 ms
202,152 KB |
testcase_27 | AC | 777 ms
201,888 KB |
testcase_28 | AC | 784 ms
202,460 KB |
testcase_29 | AC | 786 ms
202,156 KB |
testcase_30 | AC | 782 ms
202,196 KB |
testcase_31 | AC | 796 ms
202,144 KB |
testcase_32 | AC | 787 ms
201,888 KB |
testcase_33 | AC | 763 ms
202,060 KB |
testcase_34 | AC | 762 ms
202,144 KB |
testcase_35 | AC | 763 ms
202,204 KB |
testcase_36 | AC | 764 ms
202,272 KB |
testcase_37 | AC | 784 ms
202,064 KB |
testcase_38 | AC | 791 ms
201,932 KB |
testcase_39 | AC | 775 ms
201,884 KB |
testcase_40 | AC | 771 ms
202,404 KB |
testcase_41 | AC | 783 ms
202,404 KB |
testcase_42 | AC | 769 ms
202,516 KB |
testcase_43 | AC | 785 ms
202,156 KB |
testcase_44 | AC | 781 ms
202,152 KB |
testcase_45 | AC | 773 ms
201,884 KB |
testcase_46 | AC | 772 ms
202,536 KB |
testcase_47 | AC | 836 ms
202,144 KB |
testcase_48 | AC | 787 ms
202,268 KB |
testcase_49 | AC | 772 ms
201,888 KB |
testcase_50 | AC | 777 ms
201,884 KB |
testcase_51 | AC | 769 ms
202,064 KB |
testcase_52 | AC | 764 ms
201,836 KB |
testcase_53 | AC | 766 ms
202,444 KB |
testcase_54 | AC | 774 ms
202,280 KB |
testcase_55 | AC | 768 ms
202,424 KB |
testcase_56 | AC | 758 ms
201,968 KB |
testcase_57 | AC | 779 ms
202,148 KB |
testcase_58 | AC | 774 ms
202,192 KB |
testcase_59 | AC | 767 ms
202,148 KB |
testcase_60 | AC | 749 ms
202,152 KB |
testcase_61 | AC | 755 ms
201,892 KB |
testcase_62 | AC | 751 ms
202,220 KB |
testcase_63 | AC | 775 ms
203,184 KB |
testcase_64 | AC | 781 ms
203,568 KB |
testcase_65 | AC | 766 ms
203,444 KB |
testcase_66 | AC | 761 ms
203,228 KB |
testcase_67 | AC | 756 ms
203,440 KB |
testcase_68 | AC | 754 ms
203,216 KB |
testcase_69 | AC | 778 ms
206,192 KB |
ソースコード
import sys input = sys.stdin.readline mod = 998244353 max_kai = 10**6+10 kai = [1] * max_kai for i in range(1, max_kai): kai[i] = kai[i-1] * i % mod kkai = [0] * max_kai kkai[-1] = pow(kai[-1], mod - 2, mod) for i in reversed(range(1, max_kai)): kkai[i - 1] = kkai[i] * i % mod kkai_sum = [0]*(max_kai+1) for i in range(max_kai): kkai_sum[i+1] = (kkai_sum[i] + kkai[i]) % mod def cutsum(a, b): return kkai_sum[a] - kkai_sum[max(0, b)] def fft_inplace(a, w): n = len(a) m = n t = 1 while m >= 2: mh = m >> 1 for i in range(0, n, m): for s in range(mh): j, k = i+s, i+mh+s a[j], a[k] = (a[j]+a[k]) % mod, (a[j]-a[k])*w[s*t] % mod m = mh t *= 2 def ifft_inplace(a, w): n = len(a) m = 2 t = -(n >> 1) while m <= n: mh = m >> 1 for i in range(0, n, m): for s in range(mh): j, k = i+s, i+mh+s a[k] *= w[s*t] a[j], a[k] = (a[j]+a[k]) % mod, (a[j]-a[k]) % mod m <<= 1 t //= 2 n_inv = pow(n, mod-2, mod) for i in range(n): a[i] = a[i] * n_inv % mod def convolution(a, b): n2 = max(len(a) + len(b), 1) n = 1 << (n2-1).bit_length() a = a + [0] * (n-len(a)) b = b + [0] * (n-len(b)) w_root = pow(3, (mod-1)//n, mod) w = [1] * n for i in range(1, n): w[i] = w[i-1] * w_root % mod fft_inplace(a, w) fft_inplace(b, w) for i, j in enumerate(b): a[i] = a[i] * j % mod ifft_inplace(a, w) return a[:n2] n, k = map(int, input().split()) m = [int(i)+1 for i in input().split()] b = convolution(m, m[::-1]) ans = 0 for i in range(n): ans += b[i] * (kai[n-1] * cutsum(n-1, n-k-1) - kai[i]*cutsum(i, i-k)) ans %= mod for i in m: ans *= i-1 ans %= mod ans *= pow(4, mod-2, mod) ans %= mod print(ans)