結果

問題 No.2172 SEARCH in the Text Editor
ユーザー titiatitia
提出日時 2022-12-24 03:47:13
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,882 ms / 2,000 ms
コード長 864 bytes
コンパイル時間 224 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 19,200 KB
最終ジャッジ日時 2024-04-29 06:09:28
合計ジャッジ時間 24,824 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
10,752 KB
testcase_01 AC 25 ms
10,752 KB
testcase_02 AC 24 ms
10,752 KB
testcase_03 AC 1,882 ms
16,384 KB
testcase_04 AC 1,728 ms
16,384 KB
testcase_05 AC 1,737 ms
16,384 KB
testcase_06 AC 115 ms
12,032 KB
testcase_07 AC 103 ms
11,520 KB
testcase_08 AC 109 ms
11,776 KB
testcase_09 AC 234 ms
16,384 KB
testcase_10 AC 228 ms
16,128 KB
testcase_11 AC 156 ms
14,080 KB
testcase_12 AC 147 ms
12,160 KB
testcase_13 AC 168 ms
12,416 KB
testcase_14 AC 245 ms
16,384 KB
testcase_15 AC 160 ms
14,592 KB
testcase_16 AC 130 ms
12,160 KB
testcase_17 AC 135 ms
11,904 KB
testcase_18 AC 271 ms
17,408 KB
testcase_19 AC 178 ms
12,416 KB
testcase_20 AC 123 ms
13,056 KB
testcase_21 AC 292 ms
18,176 KB
testcase_22 AC 312 ms
16,256 KB
testcase_23 AC 352 ms
16,256 KB
testcase_24 AC 419 ms
16,256 KB
testcase_25 AC 418 ms
16,128 KB
testcase_26 AC 1,761 ms
16,256 KB
testcase_27 AC 1,778 ms
16,256 KB
testcase_28 AC 227 ms
12,928 KB
testcase_29 AC 257 ms
16,512 KB
testcase_30 AC 282 ms
17,920 KB
testcase_31 AC 272 ms
17,792 KB
testcase_32 AC 297 ms
19,072 KB
testcase_33 AC 296 ms
19,200 KB
testcase_34 AC 306 ms
16,384 KB
testcase_35 AC 345 ms
16,256 KB
testcase_36 AC 417 ms
16,128 KB
testcase_37 AC 411 ms
16,128 KB
testcase_38 AC 1,772 ms
16,256 KB
testcase_39 AC 1,768 ms
16,256 KB
testcase_40 AC 220 ms
12,928 KB
testcase_41 AC 255 ms
16,384 KB
testcase_42 AC 281 ms
17,792 KB
testcase_43 AC 285 ms
18,048 KB
testcase_44 AC 295 ms
19,200 KB
testcase_45 AC 293 ms
19,200 KB
testcase_46 AC 217 ms
15,744 KB
testcase_47 AC 158 ms
14,464 KB
testcase_48 AC 167 ms
14,720 KB
testcase_49 AC 277 ms
17,536 KB
testcase_50 AC 266 ms
16,896 KB
testcase_51 AC 159 ms
14,208 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