結果
問題 | No.2172 SEARCH in the Text Editor |
ユーザー | mkawa2 |
提出日時 | 2022-12-24 00:37:08 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 641 ms / 2,000 ms |
コード長 | 2,035 bytes |
コンパイル時間 | 532 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 114,048 KB |
最終ジャッジ日時 | 2024-04-29 06:06:34 |
合計ジャッジ時間 | 17,469 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
52,096 KB |
testcase_01 | AC | 41 ms
52,224 KB |
testcase_02 | AC | 42 ms
52,352 KB |
testcase_03 | AC | 641 ms
97,268 KB |
testcase_04 | AC | 493 ms
96,504 KB |
testcase_05 | AC | 429 ms
96,516 KB |
testcase_06 | AC | 110 ms
79,104 KB |
testcase_07 | AC | 154 ms
83,200 KB |
testcase_08 | AC | 163 ms
84,212 KB |
testcase_09 | AC | 302 ms
100,736 KB |
testcase_10 | AC | 292 ms
97,664 KB |
testcase_11 | AC | 267 ms
90,496 KB |
testcase_12 | AC | 195 ms
87,552 KB |
testcase_13 | AC | 209 ms
89,380 KB |
testcase_14 | AC | 320 ms
101,060 KB |
testcase_15 | AC | 242 ms
91,392 KB |
testcase_16 | AC | 113 ms
79,360 KB |
testcase_17 | AC | 185 ms
86,768 KB |
testcase_18 | AC | 330 ms
104,832 KB |
testcase_19 | AC | 204 ms
91,276 KB |
testcase_20 | AC | 203 ms
85,436 KB |
testcase_21 | AC | 342 ms
107,392 KB |
testcase_22 | AC | 178 ms
89,816 KB |
testcase_23 | AC | 179 ms
90,820 KB |
testcase_24 | AC | 207 ms
91,056 KB |
testcase_25 | AC | 194 ms
91,476 KB |
testcase_26 | AC | 521 ms
96,384 KB |
testcase_27 | AC | 513 ms
96,384 KB |
testcase_28 | AC | 264 ms
97,572 KB |
testcase_29 | AC | 309 ms
100,812 KB |
testcase_30 | AC | 353 ms
105,816 KB |
testcase_31 | AC | 348 ms
107,288 KB |
testcase_32 | AC | 462 ms
112,384 KB |
testcase_33 | AC | 459 ms
114,048 KB |
testcase_34 | AC | 166 ms
89,688 KB |
testcase_35 | AC | 171 ms
88,796 KB |
testcase_36 | AC | 170 ms
89,956 KB |
testcase_37 | AC | 179 ms
90,560 KB |
testcase_38 | AC | 540 ms
96,640 KB |
testcase_39 | AC | 304 ms
95,360 KB |
testcase_40 | AC | 252 ms
97,544 KB |
testcase_41 | AC | 320 ms
101,836 KB |
testcase_42 | AC | 346 ms
106,752 KB |
testcase_43 | AC | 333 ms
106,676 KB |
testcase_44 | AC | 364 ms
111,104 KB |
testcase_45 | AC | 371 ms
111,232 KB |
testcase_46 | AC | 304 ms
97,792 KB |
testcase_47 | AC | 249 ms
91,648 KB |
testcase_48 | AC | 251 ms
92,288 KB |
testcase_49 | AC | 334 ms
106,368 KB |
testcase_50 | AC | 327 ms
103,168 KB |
testcase_51 | AC | 230 ms
89,472 KB |
ソースコード
import sys # sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() # dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = (1 << 63)-1 # inf = (1 << 31)-1 # md = 10**9+7 md = 998244353 def z_algorithm(target): len_t = len(target) lcp = [-1]*len_t top = 1 right = 0 lcp[0] = 0 while top < len_t: while top+right < len_t and target[right] == target[top+right]: right += 1 lcp[top] = right left = 1 if right == 0: top += 1 continue while left+lcp[left] < right and left < right: lcp[top+left] = lcp[left] left += 1 top += left right -= left return lcp n = II() t = list(map(ord, SI())) m = len(t)-1 def merge(j, k): v = dp[j]+dp[k] if m: if len(ll[j]) == m: ll.append(ll[j]) else: l = ll[j]+ll[k] ll.append(l[:m]) if len(rr[k]) == m: rr.append(rr[k]) else: r = rr[j]+rr[k] rr.append(r[-m:]) lcp = z_algorithm(t+[-1]+rr[j]+ll[k]) v += lcp.count(m+1) dp.append(v%md) ll = [] rr = [] dp = [] for i in range(n): s = SI() if s[0] == "~": _, j, k = s.split() j, k = int1(j), int1(k) merge(j, k) else: s = list(map(ord, s)) if m: ll.append(s[:m]) rr.append(s[-m:]) lcp = z_algorithm(t+[-1]+s) dp.append(lcp.count(m+1)) print(dp[-1])