結果

問題 No.2020 Sum of Common Prefix Length
ユーザー 👑 rin204rin204
提出日時 2022-07-22 22:13:59
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 846 bytes
コンパイル時間 311 ms
コンパイル使用メモリ 87,224 KB
実行使用メモリ 82,892 KB
最終ジャッジ日時 2023-09-17 10:27:23
合計ジャッジ時間 5,340 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
75,488 KB
testcase_01 AC 73 ms
71,284 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 133 ms
79,132 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
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 = []

n = int(input())
V0 = Node()
Vs = [None] * n
ans = [0] * n
for i in range(n):
    S = input()
    V = V0
    for s in S:
        if s not in V.nex:
            V.nex[s] = Node()
        V = V.nex[s]
        ans[i] += 1
        for j in V.ind:
            ans[i] += 1
            ans[j] += 1
        V.ind.append(i)
    Vs[i] = V
    
Q = int(input())
for _ in range(Q):
    query = input().split()
    if query[0] == "1":
        x = int(query[1]) - 1
        s = query[2]
        V = Vs[x]
        if s not in V.nex:
            V.nex[s] = Node()
        V = V.nex[s]
        ans[x] += 1
        for j in V.ind:
            ans[x] += 1
            ans[j] += 1
        V.ind.append(i)
        Vs[x] = V

    else:
        x = int(query[1]) - 1
        print(ans[x])
0