結果
| 問題 |
No.2172 SEARCH in the Text Editor
|
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2022-12-24 03:47:13 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 1,765 ms / 2,000 ms |
| コード長 | 864 bytes |
| コンパイル時間 | 252 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 19,328 KB |
| 最終ジャッジ日時 | 2024-11-18 07:15:55 |
| 合計ジャッジ時間 | 24,076 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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