Submission #65261702


Source Code Expand

Copy
class TrieNode:
def __init__(self):
self.child={}
self.is_end=False
class Trie:
def __init__(self):
self.root=TrieNode()
def insert(self, word):
node=self.root
for ch in word:
if ch not in node.child:
node.child[ch]=TrieNode()
node = node.child[ch]
node.is_end = True
def match(self, word):
node=self.root
for ch in word:
if ch not in node.child:
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
class TrieNode:
    def __init__(self):
        self.child={}
        self.is_end=False

class Trie:
    def __init__(self):
        self.root=TrieNode()
        
    def insert(self, word):
        node=self.root
        for ch in word:
            if ch not in node.child:
                node.child[ch]=TrieNode()
            node = node.child[ch]
        node.is_end = True

    def match(self, word):
        node=self.root
        for ch in word:
            if ch not in node.child:
                return False
            node = node.child[ch]
            if node.is_end:
                return True
        return False

def solve(queries):
    trie=Trie()
    Y=[]
    y_good=[]
    count= 0

    result=[]

    for T, S in queries:
        if T==1:
            trie.insert(S)
            for i in range(len(Y)):
                if y_good[i] and trie.match(Y[i]):
                    y_good[i]=False
                    count-= 1
        else:
            f=trie.match(S)
            if not f:
                count+=1
            Y.append(S)
            y_good.append(not f)

        result.append(count)

    return result

Q=int(input())
queries=[]
for _ in range(Q):
    T,S=input().split()
    T = int(T)
    queries.append((T,S))

ans=solve(queries)
for a in ans:
    print(a)

Submission Info

Submission Time
Task E - Forbidden Prefix
User kotafuku
Language Python (PyPy 3.10-v7.3.12)
Score 0
Code Size 1357 Byte
Status TLE
Exec Time 2215 ms
Memory 298596 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 2
AC × 40
TLE × 17
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt
All 00_sample_01.txt, 00_sample_02.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 02_handmade_01.txt, 02_handmade_02.txt, 02_handmade_03.txt, 02_handmade_04.txt, 02_handmade_05.txt, 02_handmade_06.txt, 02_handmade_07.txt, 02_handmade_08.txt, 02_handmade_09.txt, 02_handmade_10.txt, 02_handmade_11.txt, 02_handmade_12.txt, 02_handmade_13.txt, 02_handmade_14.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 57 ms 76356 KiB
00_sample_02.txt AC 57 ms 76244 KiB
01_random_01.txt AC 59 ms 76540 KiB
01_random_02.txt AC 128 ms 155340 KiB
01_random_03.txt AC 128 ms 155684 KiB
01_random_04.txt AC 152 ms 183228 KiB
01_random_05.txt AC 202 ms 239264 KiB
01_random_06.txt AC 243 ms 296320 KiB
01_random_07.txt AC 82 ms 82584 KiB
01_random_08.txt AC 229 ms 130216 KiB
01_random_09.txt AC 1237 ms 169208 KiB
01_random_10.txt AC 695 ms 211644 KiB
01_random_11.txt AC 310 ms 258476 KiB
01_random_12.txt AC 256 ms 277292 KiB
01_random_13.txt AC 88 ms 84532 KiB
01_random_14.txt TLE 2213 ms 122136 KiB
01_random_15.txt TLE 2213 ms 126596 KiB
01_random_16.txt TLE 2213 ms 116368 KiB
01_random_17.txt AC 1390 ms 179420 KiB
01_random_18.txt AC 289 ms 148940 KiB
01_random_19.txt AC 83 ms 98232 KiB
01_random_20.txt AC 128 ms 153056 KiB
01_random_21.txt AC 476 ms 143816 KiB
01_random_22.txt AC 132 ms 105924 KiB
01_random_23.txt AC 612 ms 135216 KiB
01_random_24.txt TLE 2213 ms 119652 KiB
01_random_25.txt TLE 2215 ms 107648 KiB
01_random_26.txt TLE 2212 ms 108412 KiB
01_random_27.txt AC 403 ms 109648 KiB
01_random_28.txt TLE 2213 ms 120096 KiB
01_random_29.txt AC 1938 ms 129228 KiB
01_random_30.txt TLE 2212 ms 107404 KiB
01_random_31.txt AC 1050 ms 117000 KiB
01_random_32.txt AC 1122 ms 118408 KiB
01_random_33.txt AC 866 ms 100212 KiB
01_random_34.txt TLE 2213 ms 123292 KiB
01_random_35.txt TLE 2212 ms 107872 KiB
01_random_36.txt TLE 2212 ms 107588 KiB
01_random_37.txt TLE 2212 ms 107916 KiB
01_random_38.txt TLE 2212 ms 103196 KiB
01_random_39.txt TLE 2212 ms 101880 KiB
01_random_40.txt TLE 2212 ms 102160 KiB
01_random_41.txt TLE 2212 ms 102728 KiB
02_handmade_01.txt AC 240 ms 298596 KiB
02_handmade_02.txt AC 57 ms 77964 KiB
02_handmade_03.txt AC 203 ms 123784 KiB
02_handmade_04.txt TLE 2213 ms 123672 KiB
02_handmade_05.txt AC 113 ms 86836 KiB
02_handmade_06.txt AC 596 ms 87580 KiB
02_handmade_07.txt AC 100 ms 84252 KiB
02_handmade_08.txt AC 103 ms 84272 KiB
02_handmade_09.txt AC 85 ms 84040 KiB
02_handmade_10.txt AC 86 ms 84156 KiB
02_handmade_11.txt AC 90 ms 93984 KiB
02_handmade_12.txt AC 88 ms 94140 KiB
02_handmade_13.txt AC 159 ms 186300 KiB
02_handmade_14.txt AC 157 ms 186248 KiB


2025-06-30 (Mon)
12:07:05 +09:00