Problem:


Search III

Your task is to write a program of a simple dictionary which implements the following instructions:

insert str: insert a string str in to the dictionary

find str: if the distionary contains str, then print 'yes', otherwise print 'no'

Input

In the first line n, the number of instructions is given. In the following n lines, n instructions are given in the above mentioned format.

Output

Print yes or no for each find instruction in a line.

Constraints

A string consists of 'A', 'C', 'G', or 'T'

1 ≤ length of a string ≤ 12

 n ≤ 1000000 

Sample Input 1

5
insert A
insert T
insert C
find G
find A

Sample Output 1

no
yes

Sample Input 2

13
insert AAA
insert AAC
insert AGA
insert AGG
insert TTT
find AAA
find CCC
find CCC
insert CCC
find CCC
insert T
find TTT
find T

Sample Output 2

yes
no
no
yes
yes
yes

Notes

Template in C



Sample input:
5
insert A
insert T
insert C
find G
find A


Sample output:
no
yes

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [0 for i in range(22369621)]
for i in range(n):
    s = input().split(" ")
    num = 0
    p = 1
    for j in range(len(s[1])):
        if s[1][j] == "A":
            num += p * 1
        elif s[1][j] == "C":
            num += p * 2
        elif s[1][j] == "G":
            num += p * 3
        else:
            num += p * 4
        p *= 4
    if s[0][1] == "i":
        a[num] = 1
    else:
        if a[num] == 1:
            print("yes")
        else:
            print("no")

Submission status: Wrong Answer

Solution code:
def binary_search(S, key):
    left = 0
    right = len(S)
    while left < right:
        mid = int((left + right) / 2)
        # ???????????£????????????????????? return
        if S[mid] == key:
            return 'Found'
        # ??????????????????????°????????????°??????????????????????????????????????´??°
        elif S[mid] > key:
            right = mid
        # ???????????????????????§???????????°???????????? + 1 ?????????????????§??????????????´??°
        elif S[mid] < key:
            left = mid + 1
    return False


if __name__ == '__main__':
    n = int(input())
    statements = [input().split() for i in range(n)]
    inserts = []

    for data in statements:
        if data[0] == 'insert':
            inserts.append(data[1])
            continue
        print('yes' if binary_search(inserts, data[1]) else 'no')

Submission status: Wrong Answer

Solution code:
n = int(input())

class Hash:
    def __init__(self):
        self.m = 10000000
        self.T = [None] * self.m
    def insert(self, key, data):
        self.T[self.h(key)] = data
    def search(self, key):
        return self.T[self.h(key)]
    def h(self, key):
        return self.key2int(key) % self.m
    def key2int(self, key):
        return sum([['A', 'C', 'G', 'T'].index(s) + 1 for s in key])

h = Hash()
for i in range(n):
    op, st = input().split()
    if op == 'insert':
        h.insert(st, True)
    else:
        if h.search(st):
            print('yes')
        else:
            print('no')

Submission status: Wrong Answer

Solution code:
def f(s,t):
 #   As="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    As="ACGT"
    if s==t:
        return 0
    else:
        i=0
        while i<4 and s!=As[i]:
            i+=1
        while i<4 and t!=As[i]:
            i+=1
        if i<4:
            return -1
        else:
            return 1
def f3(u,v):
    m=len(u)
    if len(v)<m:
        m=len(v)
    i=0
    while i<m and u[i]==v[i]:
        i+=1
    if i>=m:
        return 0
    else:
        return f(u[i],v[i])
n=int (input ())
D=[]
for i in range(n):
    Od=input (). split ()
    l=len(D)
    gs=Od[1]
    j=0
    ts=0
    if l>0:
        r=1
        r=l%2
        p=-1
        l//=2
        j+=l
        ts=f3(gs,D[j])
    #    print(ts)
        while l>0 and ts!=0:
            if ts*p<0 and r==0:
                l-=1
            l//=2
            if ts<0:
                j-=l
                p=-1
            else:
                j+=l
                p=1
            ts=f3(gs,D[j])
            r=1
            r=l%2
    if Od[0]=="insert":
       # print(gs)
        D.insert(j+ts,gs)
      #  print(D)
    elif ts==0:
        print("yes")
    else:
        print("no")

Submission status: Wrong Answer

Solution code:
def f(s,t):
 #   As="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    As="ACGT"
    if s==t:
        return 0
    else:
        i=0
        while i<4 and s!=As[i]:
            i+=1
        while i<4 and t!=As[i]:
            i+=1
        if i<4:
            return -1
        else:
            return 1
def f3(u,v):
    m=len(u)
    if len(v)<m:
        m=len(v)
    i=0
    while i<m and u[i]==v[i]:
        i+=1
    if i>=m:
        if len(u)==len(v):
            return 0
        elif m==len(u):
            return -1
        else:
            return 1
    else:
        return f(u[i],v[i])
n=int (input ())
D=[]
for i in range(n):
    Od=input (). split ()
    l=len(D)
    gs=Od[1]
    j=0
    ts=0
    if l>0:
        p=1
        m=l//2
        j+=m
        ts=f3(gs,D[j])
    #    print(ts)
        while m>1 and ts!=0:#ight over
            if ts*p>0:
                l-=m+1
            else:
                l=m
            m=l//2
            if ts<0:
                j-=m+1
                p=-1
            else:
                j+=m+1
                p=1
            ts=f3(gs,D[j])
        if ts*p>0:
            l-=m+1
        else:
            l=m
        if l==1 and ts!=0:
            j+=ts
            ts=f3(gs,D[j])
    if Od[0]=="insert":
       # print(gs)
        if ts==-1:
            ts=0
        D.insert(j+ts,gs)
  #      print(D)
    elif ts==0:
        print("yes")
    else:
        print("no")

Submission status: Wrong Answer

Solution code:
def find(B,J):
    for i in range(len(J)):
        if B==J[i]:
            return 1
    return 0

A=[]
B=[]
J=[]

n=int(input())

for i in range(n):
    a,b=map(str, input().split())
    A.append(a)
    B.append(b)

for i in range(6):
    if A[i]=="insert":
        J.append(B[i])
    else:
        if find(B[i],J)==1:
            print("yes")
        else:
            print("no")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

class HashTable(list):
    def __init__(self, length):
        list.__init__(self)
        self.length = length
        self[:] = [None] * length

    def h1(self, key):
        return key % self.length

    def h2(self, key):
        return 1 + (key % (self.length - 1))

    def h(self, key, i):
        return (self.h1(key) + i*self.h2(key)) % self.length

    def insert(self, key):
        i = 0
        while True:
            j = self.h(key, i)
            if self[j] is None:
                self[j] = key
                return j
            else:
                i += 1
    
    def search(self, key):
        i = 0
        while True:
            j = self.h(key, i)
            if self[j] == key:
                return j
            elif self[j] is None or i >= self.length:
                return None
            else:
                i += 1

def getNum(char):
    s = ""
    for c in char:
        if c == "A":
            s += "00"
        elif c == "C":
            s += "01"
        elif c == "G":
            s += "10"
        else:
            s += "11"
    return int(s, 2)
    
    #char2num = str.maketrans("ACGT", "1234")
    #return int(char.translate(char2num))

if __name__ == '__main__':

    n = int(input())
    T = HashTable(n*10)
    C = [input().split(" ") for i in range(n)]
    C = map(lambda x:(x[0], getNum(x[1])), C)
    
    for command, num in C:
        if command == "insert":
            T.insert(num)
        else:
            if T.search(num) is None:
                print("no")
            else:
                print("yes")

Submission status: Wrong Answer

Solution code:
from collections import deque


class Tree:
    def __init__(self):
        self.children = {}

    def __contains__(self, key):
        if len(key) == 0:
            return True

        k, *rest = key 
        if k not in self.children:
            return False

        return rest in self.children[k]

    def add(self, key):
        if len(key) > 0:
            k, *rest = key 
            if k not in self.children:
                self.children[k] = self.__class__()

            self.children[k].add(rest)


class Dictionary:
    def __init__(self, maxlen):
        self.maxlen = maxlen
        self.wordq = deque()
        self.tree = Tree()

    def insert(self, word):
        for c in word:
            size = min(len(self.wordq), self.maxlen-1)
            for i in range(size):
                w = self.wordq.popleft() + c 
                self.tree.add(w)
                if len(w) < self.maxlen:
                    self.wordq.append(w)

            self.tree.add(c)
            self.wordq.append(c)

    def find(self, word):
        return word in self.tree


def run():
    count = int(input())
    words = Dictionary(12)

    for _ in range(count):
        command, v = input().split()

        if command == 'insert':
            words.insert(v)
        elif command == 'find':
            if words.find(v):
                print('yes')
            else:
                print('no')
        else:
            raise ValueError()


if __name__ == '__main__':
    run()

Submission status: Wrong Answer

Solution code:
def getkey(text):
    dic = {'A': 0, 'T': 1, 'G': 2, 'C': 3}
    sum = 0
    p = 1
    for c in text:
        sum += p*dic[c]
        p *= 5
    return sum

def h1(key):
    M = 1046572
    return key % M

dict = {}
def find(text):
    rst = dict.get(h1(getkey(text)))
    if rst:
        return rst
    else:
        return None

def insert(text):
    dict[h1(getkey(text))] = text

n = int(input())
for i in range(n):
    op, text = input().split(' ')
    if op == 'insert':
        insert(text)
    elif op == 'find':
        rst = find(text)
        if rst:
            print('yes')
        else:
            print('no')

Submission status: Wrong Answer

Solution code:
def getkey(text):
    dic = {'A': 1, 'T': 2, 'G': 3, 'C': 4}
    sum = 0
    p = 1
    for c in text:
        sum += p*dic[c]
        p *= 5
    return sum

def h1(key):
    M = 1046572
    return key % M

dict = {}
def find(text):
    rst = dict.get(h1(getkey(text)))
    if rst:
        return rst
    else:
        return None

def insert(text):
    dict[h1(getkey(text))] = text

n = int(input())
for i in range(n):
    op, text = input().split(' ')
    if op == 'insert':
        insert(text)
    elif op == 'find':
        rst = find(text)
        if rst:
            print('yes')
        else:
            print('no')

Submission status: Wrong Answer

Solution code:
#! python3
# dictionary.py

# ハッシュ法, チェイン法, 開番地法, etc
# ハッシュ法で実装する

def getkey(text):
    dic = {'A': 1, 'T': 2, 'G': 3, 'C': 4}
    sum = 0
    p = 1
    for c in text:
        sum += p*dic[c]
        p *= 5
    return sum

def h1(key):
    M = 1046572
    return key % M

def h2(key):
    M = 1046572
    return 1 + (key %(M-1))

dict = {}
def find(text):
    rst = dict.get(h2(getkey(text)))
    if rst:
        return rst
    else:
        return None

def insert(text):
    dict[h2(getkey(text))] = text

n = int(input())
for i in range(n):
    op, text = input().split(' ')
    if op == 'insert':
        insert(text)
    elif op == 'find':
        rst = find(text)
        if rst:
            print('yes')
        else:
            print('no')

Submission status: Wrong Answer

Solution code:

Submission status: Wrong Answer

Solution code:
n = int(input())
dic = {}

for i in range(n):
    com = input().split()
    c = com[0]

    if com[1] in dic:
        if c[0] == 'f': print("yes")
        else: pass

    else:
        if c[0] == 'i': dic[ c[1] ] = i
        else: print("no")

Submission status: Wrong Answer

Solution code:
#coding: Shift_JIS

def hash(str):
	v=0
	b=1
	for s in str:
		if s=='A': v+=b
		elif s=='C': v+=2*b
		elif s=='G': v+=3*b
		elif s=='T': v+=4*b
		b*=5
	return int(v%100)

dic=[[]]*100
n=int(input())
for i in range(n):
	str=input()
	com=str.split()
	key=hash(com[1])
	if com[0]=="insert":
		print(key)
		dic[key].append(com[1])
	elif com[0]=="find":
		if len(dic[key])==0:
			print("no")
		else:
			flag=0
			for s in dic[key]:
				if s==com[1]:
					print("yes")
					flag+=1
					break
			if flag==0: print("no")

Submission status: Wrong Answer

Solution code:
n = int(input())

strs = []

for i in range(n):
    s = input().split()
    print(s)
    if(s[0] == 'insert'):
        if(s[1] not in strs):
            strs.append(s[1])
    else:
        if(s[1] in strs):
            print('yes')
        else:
            print('no')
print (strs)

Submission status: Wrong Answer

Solution code:
from collections import deque

n=int(input())
S=deque()
A=deque()

for i in range(n):
	cnt=0
	str=input().split()
	if str[0][0]=="i":
		S.append(str[1])
	else:
		'''for i in range(len(S)):
			if S[i]==str[1]:
				cnt+=1
				break
		'''
		try:
			cnt=S.index(str[1])
		except:
			pass
		
		if cnt!=0:
			print("yes")
		else:
			print("no")

Submission status: Wrong Answer

Solution code:
n = int(input())
c = [0]*n
st = []

for i in range(n):
    c[i] = list(input().split())
    if c[i][0]=='insert':
        st.append(c[i][1])
        print(set(st))
        
    if c[i][0]=='find':
        if c[i][1] in st:
            print("yes")
        else:
            print("no")

Submission status: Wrong Answer

Solution code:
# ALDS1_4_C.
# ハッシュテーブル。

def get_key(_str):
    key = 0
    for i in range(len(_str)):
        if _str[i] == 'A': key += 0
        elif _str[i] == 'C': key += 1
        elif _str[i] == 'D': key += 2
        elif _str[i] == 'G': key += 3
        key *= 4
    return key
    
def main():
    n = int(input())
    for i in range(n):
        dict = {}
        command = input()
        if command[0] == 'i':
            dict[get_key(command[1])] = command[1]
        else:
            key = get_key(command[1])
            if key in dict: print('yes')
            else: print('no')
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# ALDS1_4_C.
# ハッシュテーブル。

def get_key(_str):
    key = 0
    for i in range(len(_str)):
        if _str[i] == 'A': key += 0
        elif _str[i] == 'C': key += 1
        elif _str[i] == 'G': key += 2
        elif _str[i] == 'T': key += 3
        key *= 4
    return key
    
def main():
    n = int(input())
    for i in range(n):
        dict = {}
        command = input()
        if command[0] == 'i':
            dict[get_key(command[1])] = command[1]
        else:
            key = get_key(command[1])
            if key in dict: print('yes')
            else: print('no')
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# ALDS1_4_C.
# ハッシュテーブル。

def get_key(_str):
    key = 0
    for i in range(len(_str)):
        if _str[i] == 'A': key += 0
        elif _str[i] == 'C': key += 1
        elif _str[i] == 'G': key += 2
        elif _str[i] == 'T': key += 3
        key *= 4
    return key
    
def main():
    n = int(input())
    for i in range(n):
        dict = {}
        command = input().split()
        if command[0] == 'i':
            dict[get_key(command[1])] = command[1]
        else:
            key = get_key(command[1])
            if key in dict: print('yes')
            else: print('no')
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# ALDS1_4_C.
# ハッシュテーブル。

def get_key(_str):
    key = 0
    for i in range(len(_str)):
        if _str[i] == 'A': key += 0
        elif _str[i] == 'C': key += 1
        elif _str[i] == 'G': key += 2
        elif _str[i] == 'T': key += 3
        key *= 4
    return key
    
def main():
    n = int(input())
    dict = {}
    for i in range(n):
        command = input().split()
        if command[0][0] == 'i':
            dict[get_key(command[1])] = command[1]
        else:
            key = get_key(command[1])
            if key in dict: print('yes')
            else: print('no')
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# ALDS1_4_C.
# ハッシュテーブル。

def get_key(_str):
    key = 0
    for i in range(len(_str)):
        if _str[i] == 'A': key += 1
        elif _str[i] == 'C': key += 2
        elif _str[i] == 'G': key += 3
        elif _str[i] == 'T': key += 4
        key *= 5
    return key
    
def main():
    n = int(input())
    dict = {}
    for i in range(n):
        command = input().split()
        if command[0][0] == 'i':
            dict[get_key(command[1])] = command[1]
        else:
            print(command[1])
            key = get_key(command[1])
            print(key)
            print(key in dict)
            print(dict)
            if key in dict: print('yes')
            else: print('no')
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def find(data, s):
    l = 0
    r = len(data)
    while l < r:
        ind = (l + r) // 2
        if data[ind] == s:
            return True
        elif data[ind] < s:
            l = ind + 1
        else:
            r = ind
    return False


def insert(data, s):
    if len(data) == 0:
        data.append(s)
    else:
        for i in range(len(data)):
            if s <= data[i]:
                data.insert(i, s)
                break
        data.append(s)
    return data


n = int(input())
data = []
for _ in range(n):
    command = input().split()
    if command[0] == "insert":
        data = insert(data, command[1])
    elif command[0] == "find":
        if find(data, command[1]):
            print("yes")
        else:
            print("no")

Submission status: Wrong Answer

Solution code:
def main():
    n = int(stdinput())

    d = MyDict()

    for _ in range(n):
        cmd, value = stdinput().split()
        if cmd == 'insert':
            d.insert(value)
        elif cmd == 'find':
            if d.find(value):
                print('yes')
            else:
                print('no')


class MyDict():
    def __init__(self):
        self.stacks = {
            1: [], 2: [], 3: [], 4: [], 5: [],
            6: [], 7: [], 8: [], 9: [], 10: [],
            11: [], 12: []
        }
    
    def insert(self, value):
        st = self.stacks[len(value)].append(value)
    
    def find(self, value):
        st = self.stacks[len(value)]
        return value in st

def binary_search(S, n, t):
    left = 0
    right = n - 1
    while left <= right:
        mid = (left + right) // 2
        if S[mid] == t:
            return True
        elif S[mid] > t:
            right = mid - 1
        else:
            left = mid + 1
    
    return False

def stdinput():
    from sys import stdin
    return stdin.readline().strip()

if __name__ == '__main__':
    # main()
    import cProfile
    cProfile.run('main()')

Submission status: Wrong Answer

Solution code:
class Node():
    def __init__(self, data):
        # string
        self.data = data
        self.children = dict()
        
class Tries():
    def __init__(self):
        self.head = Node("*")

    def add(self, string):
        nodelist = [Node(char) for char in string]
        cur_node = self.head
        for node in nodelist:
            char = node.data
            if char not in cur_node.children:
                cur_node.children[char] = node
                cur_node = cur_node.children[char]
            else:
                cur_node = cur_node.children[char]
        cur_node.children["*"] = 0

    def _add(self, string):
        '''
        deprecated
        '''
        
        nodelist = [Node(char) for char in string]
        cur_node = self.head
        i = 0
        
        while(i < len(nodelist)):
            node = nodelist[i]
            char = node.data
            
            if char not in cur_node.children:
                cur_node.children[char] = nodelist[i]
                cur_node = cur_node.children[char]

            else:
                # cur_node.children[char]
                cur_node = cur_node.children[char]

            i += 1
            
    def find(self, string):
        i = 0
        cur_node = self.head
        while(i <= len(string)-1):
            
            char = string[i]
            
            if char in cur_node.children:
                cur_node = cur_node.children[char]
                i += 1
            else:
                return False
        return True
                
if __name__ == "__main__":
    
    n = int(input())
    ops = []
    words = []
    for _ in range(n):
        op, word = input().split()
        ops.append(op)
        words.append(word)
    
    tries = Tries()
    for op, word in zip(ops, words):
        if op=='insert':
            tries.add(word)
        else:
            if tries.find(word)==True:
                print("yes")
            else:
                print("no")

Submission status: Wrong Answer

Solution code:
class Node():
    def __init__(self, data):
        # string
        self.data = data
        self.children = dict()
        
class Tries():
    def __init__(self):
        self.head = Node("*")

    def add(self, string):
        nodelist = [Node(char) for char in string]
        cur_node = self.head
        for node in nodelist:
            char = node.data
            if char not in cur_node.children:
                cur_node.children[char] = node
                cur_node = cur_node.children[char]
            else:
                cur_node = cur_node.children[char]
        cur_node.children["*"] = 0

    def _add(self, string):
        '''
        deprecated
        '''
        
        nodelist = [Node(char) for char in string]
        cur_node = self.head
        i = 0
        
        while(i < len(nodelist)):
            node = nodelist[i]
            char = node.data
            
            if char not in cur_node.children:
                cur_node.children[char] = nodelist[i]
                cur_node = cur_node.children[char]

            else:
                # cur_node.children[char]
                cur_node = cur_node.children[char]

            i += 1
            
    def find(self, string):
        i = 0
        cur_node = self.head
        while(i <= len(string)-1):
            
            char = string[i]
            
            if char in cur_node.children:
                cur_node = cur_node.children[char]
                i += 1
            else:
                return False
        return True
                
def main():
    n = int(input())
    ops = []
    words = []
    for _ in range(n):
        op, word = input().split()
        ops.append(op)
        words.append(word)
    
    tries = Tries()
    for op, word in zip(ops, words):
        if op=='insert':
            tries.add(word)
        else:
            if tries.find(word)==True:
                print("yes")
            else:
                print("no")

Submission status: Wrong Answer

Solution code:
n = int(input())
listA = []  # using for input
for i in range(n):
    listA.append(input())

listB = []  # dictionary
j = 0
count = 0

for i in range(n):
    if 'insert' in listA[i]:
        listB.append(listA[i][7:])
        count += 1
    else:
        for j in range(count):
            if listA[i][5:] == listB[j]:
                print('yes')
                # print(count)
                break
            else:
                print('no')
                # print(count)
                break

Submission status: Wrong Answer

Solution code:
n = int(input())
input_list = []  # using for input
for i in range(n):
    input_list.append(input())

dictionary_list = []  # dictionary
count = 0

for i in range(n):
    # print('i: ' + str(i))
    if 'insert' in input_list[i]:
        dictionary_list.append(input_list[i][7:])
        count += 1
    elif 'find' in input_list[i]:
        for j in range(count):
            # print('j: ' + str(j))
            if dictionary_list[j] == input_list[i][5:]:
                print('yes')
                break
                # print(input_list)
                # print(dictionary_list)
                # print(dictionary_list[j])
                # print('count: ' + str(count))
                # continue

            elif j == count-1:
                # print(dictionary_list)
                print('no')
                break

            # else:
            #     print('no')
                # print(input_list)
                # print(dictionary_list)
                # print(dictionary_list[j])
                # print('count: ' + str(count))
                # continue

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding:utf-8 -*-
#from __future__ import print_function
import time
import sys
import io
import re
import math
#start = time.clock()
#i = 0
a,b=[],[]
check = re.compile('insert')
n=input()
#while True:
for x in xrange(n):
    (i,f)=map(str, raw_input().split())
    if check.search(i):
        a.append(f)
    else:
        b.append(f)
#print a
#print b
for y in b:
    if y in a:
        print 'yes'
    else:
        print 'no'

Submission status: Wrong Answer

Solution code:
n = int(input())
d = {}
for i in range(n):
    print(d)
    cmd = input()
    if cmd[0] == 'i':
        d[cmd[7:]] = 0
    else:
        print('yes' if cmd[5:] in d else 'no')

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [input() for i in range(N)]
M = 1046527
T = [0 for i in range(M)]

# 各文字をバイト列にした後、それらを10進数にして、文字列として結合する
def get_key(value: str) -> int:
    converted_value = ""
    for s in value:
        b = s.encode()
        converted_value += str(b[0])
    return int(converted_value)

def h1(key: int) -> int:
    return key % M

def h2(key: int) -> int:
    move_value = 1 + (key % (M-1))
    return move_value

def h(key:int, i:int) -> int:
    hash_value = (h1(key) + i+h2(key)) % M
    return hash_value

def find(key: int) -> bool:
    i = 0
    while True:
        j = h(key, i)
        if T[j] == key:
            return True
        elif T[j] == 0 or i >= M:
            return False
        else:
            i += 1


def insert(key: int) -> None:
    i = 0
    while True:
        j = h(key, i)
        if T[j] == 0:
            T[j] = key
            return
        else:
            i += 1


for row in A:
    order, value = row.split()
    key = get_key(value)
    if order[0] == "i":
        insert(key)
    else:
        if find(key):
            print("yes")
        else:
            print("no")

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [input() for i in range(N)]
M = 10465270
T = [0 for i in range(M)]

# 各文字をバイト列にした後、それらを10進数にして、文字列として結合する
def get_key(value: str) -> int:
    converted_value = ""
    for s in value:
        b = s.encode()
        converted_value += str(b[0])
    return int(converted_value)

def h1(key: int) -> int:
    return key % M

def h2(key: int) -> int:
    move_value = 1 + (key % (M-1))
    return move_value

def h(key:int, i:int) -> int:
    hash_value = (h1(key) + i+h2(key)) % M
    return hash_value

def find(key: int) -> bool:
    i = 0
    while True:
        j = h(key, i)
        if T[j] == key:
            return True
        elif T[j] == 0 or i >= M:
            return False
        else:
            i += 1


def insert(key: int) -> None:
    i = 0
    while True:
        j = h(key, i)
        if T[j] == 0:
            T[j] = key
            return
        else:
            i += 1


for row in A:
    order, value = row.split()
    key = get_key(value)
    if order[0] == "i":
        insert(key)
    else:
        if find(key):
            print("yes")
        else:
            print("no")

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [input() for i in range(N)]
M = 1046527
T = [0 for i in range(M)]

def convert_str_to_int(s):
    if s == "A":
        return 1
    elif s == "C":
        return 2
    elif s == "G":
        return 3
    elif s == "T":
        return 4
    else:
        return 0

def get_key(value: str) -> int:
    converted_value = ""
    for s in value:
        i = convert_str_to_int(s)
        converted_value += str(i)
    return int(converted_value)

def h1(key: int) -> int:
    return key % M

def h2(key: int) -> int:
    move_value = 1 + (key % (M-1))
    return move_value

def h(key:int, i:int) -> int:
    hash_value = (h1(key) + i+h2(key)) % M
    return hash_value

def find(key: int) -> bool:
    i = 0
    while True:
        j = h(key, i)
        if T[j] == key:
            return True
        elif T[j] == 0 or i >= M:
            return False
        else:
            i += 1


def insert(key: int) -> None:
    i = 0
    while True:
        j = h(key, i)
        if T[j] == 0:
            T[j] = key
            return
        else:
            i += 1


for row in A:
    order, value = row.split()
    key = get_key(value)
    if order[0] == "i":
        insert(key)
    else:
        if find(key):
            print("yes")
        else:
            print("no")

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [input() for i in range(N)]
M = 10465270
T = [0 for i in range(M)]

def convert_str_to_int(s):
    if s == "A":
        return 1
    elif s == "C":
        return 2
    elif s == "G":
        return 3
    elif s == "T":
        return 4
    else:
        return 0

def get_key(value: str) -> int:
    converted_value = ""
    for s in value:
        i = convert_str_to_int(s)
        converted_value += str(i)
    return int(converted_value)

def h1(key: int) -> int:
    return key % M

def h2(key: int) -> int:
    move_value = 1 + (key % (M-1))
    return move_value

def h(key:int, i:int) -> int:
    hash_value = (h1(key) + i+h2(key)) % M
    return hash_value

def find(key: int) -> bool:
    i = 0
    while True:
        j = h(key, i)
        if T[j] == key:
            return True
        elif T[j] == 0 or i >= M:
            return False
        else:
            i += 1


def insert(key: int) -> None:
    i = 0
    while True:
        j = h(key, i)
        if T[j] == 0:
            T[j] = key
            return
        else:
            i += 1


for row in A:
    order, value = row.split()
    key = get_key(value)
    if order[0] == "i":
        insert(key)
    else:
        if find(key):
            print("yes")
        else:
            print("no")

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [input() for i in range(N)]
M = N * 10
T = [0 for i in range(M)]

def convert_str_to_int(s):
    if s == "A":
        return 1
    elif s == "C":
        return 2
    elif s == "G":
        return 3
    elif s == "T":
        return 4
    else:
        return 0

def get_key(value: str) -> int:
    converted_value = ""
    for s in value:
        i = convert_str_to_int(s)
        converted_value += str(i)
    return int(converted_value)

def h1(key: int) -> int:
    return key % M

def h2(key: int) -> int:
    move_value = 1 + (key % (M-1))
    return move_value

def h(key:int, i:int) -> int:
    hash_value = (h1(key) + i+h2(key)) % M
    return hash_value

def find(key: int) -> bool:
    i = 0
    while True:
        j = h(key, i)
        if T[j] == key:
            return True
        elif T[j] == 0 or i >= M:
            return False
        else:
            i += 1


def insert(key: int) -> None:
    i = 0
    while True:
        j = h(key, i)
        if T[j] == 0:
            T[j] = key
            return
        else:
            i += 1


for row in A:
    order, value = row.split()
    key = get_key(value)
    if order[0] == "i":
        insert(key)
    else:
        if find(key):
            print("yes")
        else:
            print("no")