結果

問題 No.2524 Stripes
ユーザー titiatitia
提出日時 2023-11-16 04:24:22
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 3,265 bytes
コンパイル時間 219 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 283,428 KB
最終ジャッジ日時 2023-11-16 04:25:30
合計ジャッジ時間 66,138 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
55,600 KB
testcase_01 AC 44 ms
55,600 KB
testcase_02 WA -
testcase_03 AC 3,929 ms
225,144 KB
testcase_04 RE -
testcase_05 AC 2,360 ms
157,552 KB
testcase_06 AC 3,976 ms
223,336 KB
testcase_07 AC 6,298 ms
261,176 KB
testcase_08 AC 5,270 ms
265,720 KB
testcase_09 AC 1,295 ms
118,520 KB
testcase_10 AC 3,547 ms
206,716 KB
testcase_11 AC 536 ms
87,940 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 AC 6,546 ms
272,908 KB
testcase_16 TLE -
testcase_17 AC 6,481 ms
262,468 KB
testcase_18 WA -
testcase_19 AC 42 ms
55,600 KB
testcase_20 WA -
testcase_21 RE -
testcase_22 AC 46 ms
55,600 KB
testcase_23 AC 45 ms
55,600 KB
testcase_24 RE -
testcase_25 AC 45 ms
55,600 KB
testcase_26 RE -
testcase_27 AC 45 ms
55,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

from copy import deepcopy

# FFT
# mod=998244353 における、NTTによる高速フーリエ変換、畳み込み
# 他の提出を参考にしており、あまり理解できていません……
mod=998244353
 
Weight=[1, 998244352, 911660635, 372528824, 929031873, 452798380, 922799308, 781712469, 476477967, 166035806, 258648936, 584193783, 63912897, 350007156, 666702199, 968855178, 629671588, 24514907, 996173970, 363395222, 565042129, 733596141, 267099868, 15311432, 0]
Weight_inv=[1, 998244352, 86583718, 509520358, 337190230, 87557064, 609441965, 135236158, 304459705, 685443576, 381598368, 335559352, 129292727, 358024708, 814576206, 708402881, 283043518, 3707709, 121392023, 704923114, 950391366, 428961804, 382752275, 469870224, 0]
 
def fft(A,n,h,inverse=0):
 
    if inverse==0:
    
        for i in range(h):
            m=1<<(h-i-1)
            for j in range(1<<i):
                w=1     
                ij=j*m*2
                
                wk=Weight[h-i]
                    
                for k in range(m):
                    A[ij+k],A[ij+k+m]=(A[ij+k]+A[ij+k+m])%mod,(A[ij+k]-A[ij+k+m])*w%mod
                    w=w*wk%mod
    else:
        for i in range(h):
            m=1<<i
            for j in range(1<<(h-i-1)):
                w=1     
                ij=j*m*2
                
                wk=Weight_inv[i+1]
                    
                for k in range(m):
                    A[ij+k],A[ij+k+m]=(A[ij+k]+A[ij+k+m]*w)%mod,(A[ij+k]-A[ij+k+m]*w)%mod
                    w=w*wk%mod
        
 
    if inverse==1:
        INV_n=pow(n,mod-2,mod)
        for i in range(n):
            A[i]=A[i]*INV_n%mod
 
    return A
 
def convolution(A,B):
    
    FFTLEN=len(A)+len(B)-1
    h=FFTLEN.bit_length()
    LEN=2**h
 
    A+=[0]*(LEN-len(A)) # A,Bのサイズを2ベキに揃える
    B+=[0]*(LEN-len(B))
 
    A_FFT=fft(A,LEN,h)
    B_FFT=fft(B,LEN,h)
 
    for i in range(len(A)):
        A[i]=A[i]*B[i]%mod
 
    A=fft(A,LEN,h,1)
 
    return A[:FFTLEN]

# 行列の計算(numpyを使えないとき,modを使用)
def prod(A,B,k,l,m):# A:k*l,B:l*m
    #print(A,B)
    C=[[None for i in range(m)] for j in range(k)]

    for i in range(k):
        for j in range(m):
            ANS=[0]
            for pl in range(l):
                #print((A[i][pl][:],B[pl][j][:]),convolution(A[i][pl][:],B[pl][j][:]))
                ANS=plus(ANS,convolution(A[i][pl][:],B[pl][j][:]))

            #print(ANS)

            C[i][j]=ANS

    #print(C)

    return C

def plus(A,B):
    C=[0]*max(len(A),len(B))

    for i in range(len(A)):
        C[i]+=A[i]

    for i in range(len(B)):
        C[i]+=B[i]

    return C

N=int(input())
S=input().strip()

A=[[[1],[0]],[[0,1],[1]]]
B=[[[1],[0,1]],[[0],[1]]]

X=[]

for s in S:
    if s=="R":
        X.append(deepcopy(A))
    else:
        X.append(deepcopy(B))

while len(X)>=2:
    Y=[]

    for i in range(0,len(X),2):
        if i+1<len(X):
            Y.append(prod(X[i],X[i+1],2,2,2))
        else:
            Y.append(X[i])
    X=Y

#print("!",X)

Y=[[[1]],[[1]]]
ANS=prod(X[0],Y,2,2,1)

#print(ANS)

for i in range(1,N+1):
    if i<len(ANS[0][0]):
        print((ANS[0][0][i]+ANS[1][0][i])%mod)
    else:
        print(0)

0