結果
| 問題 | 
                            No.2172 SEARCH in the Text Editor
                             | 
                    
| コンテスト | |
| ユーザー | 
                             titia
                         | 
                    
| 提出日時 | 2022-12-24 03:46:07 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 400 ms / 2,000 ms | 
| コード長 | 865 bytes | 
| コンパイル時間 | 165 ms | 
| コンパイル使用メモリ | 81,988 KB | 
| 実行使用メモリ | 84,904 KB | 
| 最終ジャッジ日時 | 2024-11-18 07:16:51 | 
| 合計ジャッジ時間 | 9,911 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 49 | 
ソースコード
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)
            
            
            
        
            
titia