結果

問題 No.1195 数え上げを愛したい(文字列編)
ユーザー 37zigen37zigen
提出日時 2020-08-23 06:59:21
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 982 bytes
コンパイル時間 182 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 113,648 KB
最終ジャッジ日時 2024-04-23 16:45:57
合計ジャッジ時間 21,332 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 TLE -
testcase_02 TLE -
testcase_03 AC 1,689 ms
76,848 KB
testcase_04 AC 1,279 ms
78,496 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import queue
import numpy as np

MOD=998244353

def convolve(f,g):
    fft=np.fft.rfft
    ifft=np.fft.irfft
    Lf=len(f)
    Lg=len(g)
    L=Lf+Lg-1
    fft_len=1<<L.bit_length()
    fl=f&(1<<15)-1
    gl=g&(1<<15)-1
    fh=f>>15
    gh=g>>15
    def conv(f,g):
        return ifft(fft(f,fft_len)*fft(g,fft_len))[:L]

    x=conv(fl,gl)%MOD
    y=conv(fl+fh,gl+gh)%MOD
    z=conv(fh,gh)%MOD
    a,b,c=map(lambda x : (x+.5).astype(np.int64) ,[x,y,z])
    return (a+((b-a-c)<<15)+(c<<30))%MOD

MAX=3*(10**5)+10
fac=[1]*MAX
ifac=[1]*MAX
for i in range(2,MAX):
    fac[i]=fac[i-1]*i%MOD
ifac[-1]=pow(fac[-1],MOD-2,MOD)
for i in range(MAX-2,0,-1):
    ifac[i]=(i+1)*ifac[i+1]%MOD

S=input()
cnt=[0]*27
for s in S:
    cnt[ord(s)-ord('a')]+=1
poly=np.array([1],np.int64)
for i in range(27):
    f=np.array([0]*(cnt[i]+1),np.int64)
    for j in range(cnt[i]+1):
        f[j]=ifac[j]
    poly=convolve(poly,f)

ans=0
for i in range(1,len(poly)):
    ans=(ans+poly[i]*fac[i])%MOD
print(ans)
0