結果

問題 No.2172 SEARCH in the Text Editor
ユーザー titiatitia
提出日時 2022-12-24 03:46:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 469 ms / 2,000 ms
コード長 865 bytes
コンパイル時間 280 ms
コンパイル使用メモリ 86,936 KB
実行使用メモリ 86,240 KB
最終ジャッジ日時 2023-08-11 13:48:25
合計ジャッジ時間 12,099 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,504 KB
testcase_01 AC 74 ms
71,340 KB
testcase_02 AC 75 ms
71,204 KB
testcase_03 AC 469 ms
79,376 KB
testcase_04 AC 236 ms
79,580 KB
testcase_05 AC 241 ms
79,700 KB
testcase_06 AC 123 ms
78,976 KB
testcase_07 AC 146 ms
79,804 KB
testcase_08 AC 151 ms
80,240 KB
testcase_09 AC 183 ms
83,512 KB
testcase_10 AC 177 ms
82,920 KB
testcase_11 AC 147 ms
80,980 KB
testcase_12 AC 155 ms
81,116 KB
testcase_13 AC 164 ms
81,420 KB
testcase_14 AC 197 ms
84,468 KB
testcase_15 AC 162 ms
81,756 KB
testcase_16 AC 133 ms
79,056 KB
testcase_17 AC 154 ms
80,884 KB
testcase_18 AC 194 ms
84,312 KB
testcase_19 AC 159 ms
82,048 KB
testcase_20 AC 147 ms
80,572 KB
testcase_21 AC 185 ms
84,356 KB
testcase_22 AC 138 ms
79,652 KB
testcase_23 AC 139 ms
79,660 KB
testcase_24 AC 146 ms
79,772 KB
testcase_25 AC 148 ms
79,820 KB
testcase_26 AC 245 ms
79,820 KB
testcase_27 AC 239 ms
79,780 KB
testcase_28 AC 189 ms
83,556 KB
testcase_29 AC 214 ms
84,372 KB
testcase_30 AC 243 ms
86,240 KB
testcase_31 AC 238 ms
85,820 KB
testcase_32 AC 183 ms
86,108 KB
testcase_33 AC 186 ms
86,156 KB
testcase_34 AC 140 ms
79,732 KB
testcase_35 AC 142 ms
79,512 KB
testcase_36 AC 150 ms
79,908 KB
testcase_37 AC 150 ms
79,700 KB
testcase_38 AC 234 ms
79,784 KB
testcase_39 AC 241 ms
79,800 KB
testcase_40 AC 188 ms
83,332 KB
testcase_41 AC 218 ms
84,472 KB
testcase_42 AC 215 ms
85,460 KB
testcase_43 AC 214 ms
85,000 KB
testcase_44 AC 181 ms
85,936 KB
testcase_45 AC 180 ms
86,000 KB
testcase_46 AC 166 ms
82,996 KB
testcase_47 AC 151 ms
81,012 KB
testcase_48 AC 150 ms
81,232 KB
testcase_49 AC 182 ms
84,056 KB
testcase_50 AC 176 ms
82,976 KB
testcase_51 AC 145 ms
81,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

mod=998244353

N=int(input())
T=input().strip()
LEN=len(T)

COUNT=[-1]*N
BEGIN=[""]*N
END=[""]*N

def str_count(S,T):
    ANS=0
    for i in range(len(S)):
        if S[i:i+len(T)]==T:
            ANS+=1
    return ANS

for i in range(N):
    A=input().split()

    if len(A)==1:
        COUNT[i]=str_count(A[0],T)

        if LEN!=1:
            BEGIN[i]=A[0][:LEN-1]
            END[i]=A[0][-LEN+1:]
    else:
        x,y=A[1],A[2]
        x=int(x)-1
        y=int(y)-1

        k=END[x]+BEGIN[y]
        COUNT[i]=(COUNT[x]+COUNT[y]+str_count(k,T))%mod

        if len(BEGIN[x])<LEN-1:
            BEGIN[i]=(BEGIN[x]+BEGIN[y])[:LEN-1]
        else:
            BEGIN[i]=BEGIN[x]

        if len(END[y])<LEN-1:
            END[i]=(END[x]+END[y])[-LEN+1:]
        else:
            END[i]=END[y]
        
print(COUNT[-1]%mod)
0