結果

問題 No.2020 Sum of Common Prefix Length
コンテスト
ユーザー rin204
提出日時 2022-07-22 22:13:59
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 846 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 289 ms
コンパイル使用メモリ 85,632 KB
実行使用メモリ 345,852 KB
最終ジャッジ日時 2026-03-25 14:44:06
合計ジャッジ時間 59,020 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 8 WA * 13 TLE * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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