結果

問題 No.2020 Sum of Common Prefix Length
ユーザー 👑 rin204rin204
提出日時 2022-07-22 22:38:27
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,432 bytes
コンパイル時間 1,485 ms
コンパイル使用メモリ 86,832 KB
実行使用メモリ 101,056 KB
最終ジャッジ日時 2023-09-17 11:09:12
合計ジャッジ時間 16,198 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,528 KB
testcase_01 AC 72 ms
71,252 KB
testcase_02 AC 73 ms
71,132 KB
testcase_03 AC 155 ms
78,428 KB
testcase_04 AC 139 ms
78,156 KB
testcase_05 AC 138 ms
78,168 KB
testcase_06 AC 130 ms
77,992 KB
testcase_07 AC 1,544 ms
98,040 KB
testcase_08 AC 1,583 ms
98,640 KB
testcase_09 AC 1,695 ms
97,996 KB
testcase_10 AC 1,540 ms
97,964 KB
testcase_11 AC 1,176 ms
98,016 KB
testcase_12 AC 1,434 ms
97,968 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

class Node:
    def __init__(self):
        self.nex = {}
        self.ind = []
        self.tot = 0

n = int(input())
V0 = Node()
Vs = [None] * n
ans = [0] * n
SS = []
for i in range(n):
    S = input()
    SS.append(list(S))
    V = V0
    for s in S:
        if s not in V.nex:
            V.nex[s] = Node()
        V = V.nex[s]
        V.tot += 1
    Vs[i] = V

B = 800
for i, S in enumerate(SS):
    V = V0
    flg = len(S) >= B
    for s in S:
        V = V.nex[s]
        ans[i] += V.tot
        if flg:
            V.ind.append(i)

Q = int(input())
for _ in range(Q):
    query = input().split()
    if query[0] == "1":
        i = int(query[1]) - 1
        s = query[2]
        SS[i].append(s)
        V = Vs[i]
        if s not in V.nex:
            V.nex[s] = Node()
        V = V.nex[s]
        V.tot += 1
        for j in V.ind:
            ans[j] += 1
        le = len(SS)
        if le < B:
            pass
        elif le == B:
            ans[i] = 0
            V = V0
            for s in SS[i]:
                V = V.nex[s]
                ans[i] += V.tot
                V.ind.append(i)
        else:
            V.ind.append(i)
            ans[i] += V.tot
        Vs[i] = V

    else:
        i = int(query[1]) - 1
        le = len(SS[i])
        if le < B:
            ans[i] = 0
            V = V0
            for s in SS[i]:
                V = V.nex[s]
                ans[i] += V.tot
        print(ans[i])
0