Problem:


String Search

  Determine whether a text T includes a pattern P. Your program should answer for given queries consisting of P_i.

Input

  In the first line, a text T is given. In the second line, an integer Q denoting the number of queries is given. In the following Q lines, the patterns P_i are given respectively.

Output

  For each question, print 1 if the text includes P_i, or print 0 otherwise.

Constraints

  
 1 ≤ length of T ≤ 1000000 

  
 1 ≤ length of P_i ≤ 1000 

  
 1 ≤ Q ≤ 10000 

  
The input consists of alphabetical characters and digits

Sample Input 1

aabaaa
4
aa
ba
bb
xyz

Sample Output 1

1
1
0
0



Sample input:
aabaaa
4
aa
ba
bb
xyz


Sample output:
1
1
0
0

Submission status: Wrong Answer

Solution code:
base = 127
mask = (1 << 32) - 1


def calc_hash(f, pl, tl):
    dl = tl - pl
    tmp = set()

    t = 1
    for _ in range(pl):
        t = (t * base) & mask
    e = 0
    for i in range(pl):
        e = (e * base + f[i]) & mask
    for i in range(dl):
        tmp.add(e)
        e = (e * base - t * f[i] + f[i + pl]) & mask
    tmp.add(e)
    return tmp


t = [ord(c) for c in input().strip()]
tl = len(t)
q = int(input())
h = dict()
while q:
    p = [ord(c) for c in input().strip()]
    pl = len(p)
    if pl > tl:
        print(0)
        q -= 1
        continue
    bs = min(10, pl)
    keys = calc_hash(p, bs, pl)
    if bs not in h:
        h[bs] = calc_hash(t, bs, tl)
    print(1 if keys.issubset(h[bs]) else 0)
    q -= 1

Submission status: Wrong Answer

Solution code:
#coding:utf-8

def MSM(T,P):
    Tlist=list(T)
    Plist=list(P)
    if len(Tlist)<len(Plist):
        return 0
    for i in range(len(Tlist)):
        ans=0
        if Tlist[i]==Plist[0]:
            ans+=1
            if len(Plist)>1 and len(Tlist[i:])>len(Plist):
                for j in range(1,len(Plist)):
                    if Plist[j]==Tlist[i+j] and i+j<=len(Tlist):
                        ans+=1
        if ans==len(Plist):
            return 1
    return 0

if __name__=="__main__":
    T=input()
    n=int(input())
    ans=[]
    for i in range(n):
        P=input()
        ans.append(MSM(T,P))
    for i in range(n):
        print(ans[i])

Submission status: Wrong Answer

Solution code:
import sys
CSIZE = 256
buff = input()
n = int(input())



def make_BM_table(pattern):
    table = [len(pattern) ] * CSIZE
    for i in range(len(pattern)):
        dist = len(pattern) - i - 1
        table[ord(pattern[i])] = dist
    return table

def BM_search(pattern,buff):
    table = make_BM_table(pattern)
    i = len(pattern) - 1
    while i < len(buff) - 1:
        for k in range(len(pattern)):
            if pattern[len(pattern)-k-1] != buff[i - k]:
                i += max(table[ord(buff[i-k])] - (-k-1) ,1)
                break
        else: 
            print("1")
            break
    else:
        print("0")
        
for i in range(n):
    pattern = input()
    BM_search(pattern, buff)

Submission status: Wrong Answer

Solution code:
T = input()
n = int(input())


for i in range(n):
    P = input()
    
    if T in P:
        print(1)
    else:
        print(0)

Submission status: Wrong Answer

Solution code:

def search1(T,P):
    
    if P in T:
        print(1)
    else:
        print(0)

def search2(T,line):
    
    if P in line:
        return True
    else:
        return False
    

T = input()
n = int(input())


for i in range(n):
    

    P = input()
    
    if len(P) < 500:
        
        search1(T,P)

    else:

        line = P[:500]
        if search2(T,line):
            search1(T,P)
        else:
            print(0)

Submission status: Wrong Answer

Solution code:
#coding:utf-8

# ?§????????????????????????????
def make_BM_table(P):
    CSIZE = 256
    bm_table = [len(P)]*CSIZE
    for i in range(len(P)-1):
        bm_table[ord(P[i])] = len(P)-i
    
    return bm_table

# ?????????????´¢
def BM_string_search(T,P):
    
    # ??????????????´????????????
    if len(T) == 0 or len(P) == 0 or len(P) > len(T):
        return False

    bm_table = make_BM_table(P)

    # k???T????????????P?????????
    k = len(T)-1

    while True:
        
        # k???len(T)??\???????????£??????break
        if k >= len(T):
            break

        # i???P?????????????????????????????????
        i = len(P)-1 
        # h???T?????????????????????????????????
        h = k
        
        while i >= 0 and h > -1 and P[i] == T[h]:
            i -= 1
            h -= 1
        
        # i<0?????????P??¨?????´??????
        if i < 0:
            return True
        
        # ??¢?´¢????????¨????????§????????£????????????????????????
        else:
            k += max(bm_table[ord(T[i])],len(P)-h)
    
    return False


if __name__ == '__main__':

    # ?????????????????\???
    T = input()
    # ????´¢?????????????????°?????\???
    n = int(input())

    # ????????????????????????????????????????????\???
    for i in range(n):
        P = input()

        if BM_string_search(T,P):
            print(1)
        else:
            print(0)

Submission status: Wrong Answer

Solution code:
#coding:utf-8

# ?§????????????????????????????
def make_BM_table(P):
    CSIZE = 128
    bm_table = [len(P)]*CSIZE

    for i in range(len(P)-1):
        bm_table[ord(P[i])] = len(P)-i-1

    print(bm_table)

    return bm_table

# ?????????????´¢
def BM_string_search(T,P):

    # ?§????????????????????????????
    bm_table = make_BM_table(P)

    i = len(P)-1

    while i < len(T):
        j = len(P)-1

        while T[i] == P[j]:
            
            # ??????
            if j == 0:
                return True

            i -= 1
            j -= 1

        i += max(bm_table[ord(T[i])],len(P)-j)

    return False


if __name__ == '__main__':

    # ?????????????????\???
    T = input()
    # ????´¢?????????????????°?????\???
    n = int(input())

    # ????????????????????????????????????????????\???
    for i in range(n):
        P = input()
    
        if BM_string_search(T,P):
            print(1)
        else:
            print(0)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
original_string = list(map(ord, list(input())))
check_string_count = int(input())
checkers = [list(map(ord,list(input()))) for i in range(check_string_count)]
for checker in checkers:
    found = False
    for index in range(0, len(original_string)-len(checker)):
        if original_string[index] == checker[0]:
            found = True
            for checker_index in range(len(checker)):
                if checker[checker_index] != original_string[index + checker_index]:
                    found = False
                    break
            if found:
                print(1)
                break
    if not found:
        print(0)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
original_string = list(map(ord, list(input())))
check_string_count = int(input())
checkers = [list(map(ord,list(input()))) for i in range(check_string_count)]
for checker in checkers:
    found = False
    sum_of_checker = sum(checker)
    if len(checker) > len(original_string):
        print(0)
        continue
    for index in range(0, len(original_string)):
        if (len(original_string)-len(checker)) < index:
            break
        if original_string[index] == checker[0]:
            found = True
            sum_of_origin = sum(original_string[index:index+len(checker)])
            if sum_of_origin != sum_of_checker:
                found = False
            if found:
                print(1)
                break
    if not found:
        print(0)

Submission status: Wrong Answer

Solution code:
base = 127
mask = (1 << 32) - 1


def calc_hash(f, pl, tl):
    dl = tl - pl
    tmp = set()

    t = 1
    for _ in range(pl):
        t = (t * base) & mask
    e = 0
    for i in range(pl):
        e = (e * base + f[i]) & mask
    for i in range(dl):
        tmp.add(e)
        e = (e * base - t * f[i] + f[i + pl]) & mask
    tmp.add(e)
    return tmp


t = [ord(c) for c in input().strip()]
tl = len(t)
q = int(input())
ps = [input().strip() for _ in range(q)]
h = dict()
c = dict()
a = []
for p in ps:
    if p in c:
        a.append(c[p])
        continue
    p = [ord(c) for c in p]
    pl = len(p)
    if pl > tl:
        a.append(0)
        continue
    bs = min(16, pl)
    keys = calc_hash(p, bs, pl)
    if bs not in h:
        h[bs] = calc_hash(t, bs, tl)
    a.append(1 if keys.issubset(h[bs]) else 0)
print('\n'.join(map(str, a)))

Submission status: Wrong Answer

Solution code:
base = 127
mask = (1 << 32) - 1


def calc_hash(f, pl, tl):
    dl = tl - pl
    tmp = set()

    t = 1
    for _ in range(pl):
        t = (t * base) & mask
    e = 0
    for i in range(pl):
        e = (e * base + f[i]) & mask
    for i in range(dl):
        tmp.add(e)
        e = (e * base - t * f[i] + f[i + pl]) & mask
    tmp.add(e)
    return tmp


t = [ord(c) for c in input().strip()]
tl = len(t)
q = int(input())
ps = [input().strip() for _ in range(q)]
h = dict()
c = dict()
a = []
for p in ps:
    if p in c:
        a.append(c[p])
        continue
    p = [ord(c) for c in p]
    pl = len(p)
    if pl > tl:
        a.append(0)
        continue
    bs = min(17, pl)
    keys = calc_hash(p, bs, pl)
    if bs not in h:
        h[bs] = calc_hash(t, bs, tl)
    a.append(1 if keys.issubset(h[bs]) else 0)
print('\n'.join(map(str, a)))

Submission status: Wrong Answer

Solution code:
base = 127
mask = (1 << 32) - 1


def calc_hash(f, pl, tl):
    dl = tl - pl
    tmp = set()

    t = 1
    for _ in range(pl):
        t = (t * base) & mask
    e = 0
    for i in range(pl):
        e = (e * base + f[i]) & mask
    for i in range(dl):
        tmp.add(e)
        e = (e * base - t * f[i] + f[i + pl]) & mask
    tmp.add(e)
    return tmp


t = [ord(c) for c in input().strip()]
tl = len(t)
q = int(input())
ps = [input().strip() for _ in range(q)]
h = dict()
a = []
hash_len = 18
for p in ps:
    p = [ord(c) for c in p]
    pl = len(p)
    if pl > tl:
        a.append(0)
        continue
    bs = min(hash_len, pl)
    keys = calc_hash(p, bs, pl)
    if bs not in h:
        h[bs] = calc_hash(t, bs, tl)
    a.append(1 if keys.issubset(h[bs]) else 0)
print('\n'.join(map(str, a)))

Submission status: Wrong Answer

Solution code:
x = input()
n = int(input())


def check(string,word):
    search_state = 0
    l = len(string)
    i = 0
    while (i < l):
        # print(string[i])
        if i+search_state < l and string[i+search_state] == word[search_state]:
            search_state += 1
            if search_state == len(word):
                return 1
        else:
            i += max(search_state,1)
            search_state = 0
            
    return 0
            
# print(check(x,'baa'))
    
for i in range(n):
    y = input()
    print(check(x,y))

Submission status: Wrong Answer

Solution code:
x = input()
n = int(input())


def check(string,word):
    search_state = 0
    first_match = 0
    l = len(string)
    i = 0
    while (i < l):
        # print(string[i])
        if i+search_state < l and string[i+search_state] == word[search_state]:
            if first_match == 0:
                first_match = search_state
            search_state += 1
            if search_state == len(word):
                return 1
        else:
            i += max(min(first_match,search_state),1)
            search_state = 0
            
    return 0
            
# print(check(x,'baa'))
    
for i in range(n):
    y = input()
    print(i + check(x,y))
    
# for i in range(n):
#     y = input()
#     print(str(i) + y)
#     # if y in x:
    #     print(i + 1)
    # else:
    #     print(i + 0)

Submission status: Wrong Answer

Solution code:
x = input()
n = int(input())


def check(string,word):
    search_state = 0
    first_match = 0
    l = len(string)
    i = 0
    while (i < l):
        if i+len(word) >= l:
            break
        if word[0] != string[i] or word[-1] != string[i+len(word)-1]:
            i += 1
            continue
        # print(string[i])
        if string[i+search_state] == word[search_state]:
            if first_match == 0:
                first_match = search_state
            search_state += 1
            if search_state == len(word):
                return 1
        else:
            i += max(min(first_match,search_state),1)
            search_state = 0
            
    return 0
            
# print(check(x,'baa'))
    
for i in range(n):
    y = input()
    print(i + check(x,y))
    
# for i in range(n):
#     y = input()
#     print(str(i) + y)
#     # if y in x:
    #     print(i + 1)
    # else:
    #     print(i + 0)

Submission status: Wrong Answer

Solution code:
x = input()
n = int(input())


def check(string,word):
    search_state = 0
    first_match = 0
    l = len(string)
    i = 0
    while (i < l):
        if i+len(word) >= l:
            break
        if word[0] != string[i] or word[-1] != string[i+len(word)-1]:
            i += 1
            continue
        # print(string[i])
        if string[i+search_state] == word[search_state]:
            if first_match == 0:
                first_match = search_state
            search_state += 1
            if search_state == len(word):
                return 1
        else:
            i += max(min(first_match,search_state),1)
            search_state = 0
            
    return 0
            
# print(check(x,'baa'))
    
for i in range(n):
    y = input()
    print(i + check(x,y))
    
# for i in range(n):
#     y = input()
#     print(str(i) + y)
#     # if y in x:
    #     print(i + 1)
    # else:
    #     print(i + 0)

Submission status: Wrong Answer

Solution code:
x = input()
n = int(input())


def check(string,word):
    search_state = 0
    first_match = 0
    l = len(string)
    i = 0
    while (i < l):
        if i+len(word) >= l:
            break
        if word[0] != string[i] or word[-1] != string[i+len(word)-1]:
            i += 1
            continue
        # print(string[i])
        if string[i+search_state] == word[search_state]:
            if first_match == 0:
                first_match = search_state
            search_state += 1
            if search_state == len(word):
                return 1
        else:
            i += max(min(first_match,search_state),1)
            search_state = 0
            
    return 0
            
# print(check(x,'baa'))
    
for i in range(n):
    y = input()
    print(check(x,y))
    
# for i in range(n):
#     y = input()
#     print(str(i) + y)
#     # if y in x:
    #     print(i + 1)
    # else:
    #     print(i + 0)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import OrderedDict


def main():
    inputStr = sys.stdin.read()
    lines = inputStr.split("\n")
    text, words = lines[0], lines[2:-1]
    words_by_length = {}
    for i, word in enumerate(words):
        if len(word) in words_by_length:
            words_by_length[len(word)].append((i, word))
        else:
            words_by_length[len(word)] = [(i, word)]
    words_by_length = OrderedDict(sorted(words_by_length.items(), key=lambda t: t[0]))
    found_indices = set([])
    text_length = len(text)
    for i in range(text_length):
        for word_length, words_by_index in words_by_length.items():
            if i + word_length >= text_length:
                break
            sliced = text[i:(i + word_length)]
            founds = []
            for i, (index, word) in enumerate(words_by_index):
                if sliced == word:
                    found_indices.add(index)
                    founds.insert(0, i)
            for i in founds:
                words_by_index.pop(i)

    for i in range(len(words)):
        if i in found_indices:
            print(1)
        else:
            print(0)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


class IndexMatch:
    shift = 40
    size = 33554393

    def __init__(self, text):
        self.text = text
        self.index = self._create_index()

    def _create_index(self):
        index = defaultdict(list)
        index[self.text[0]].append(0)

        for i in range(1, len(self.text)):
            index[self.text[i-1:i+1]].append(i-1)
            index[self.text[i]].append(i)

        return index

    def match(self, search_text):
        def _match(text):
            ls = len(text)
            if ls <= 2:
                return [(i, i+ls-1) for i in self.index[text]]

            mid = ls // 2
            pre = _match(text[:mid])
            post = _match(text[mid:])

            if len(pre) == 0 or len(post) == 0:
                return []

            indices = []
            for (s1, e1) in pre:
                (s2, e2) = self._find(post, e1+1)
                if s2 > 0:
                    indices.append((s1, e2))

            return indices

        return len(_match(search_text)) > 0

    def _find(self, ts, i):
        if len(ts) == 0:
            return (-1, -1)
        mid = len(ts) // 2
        s, e = ts[mid]
        if s > i:
            return self._find(ts[mid+1:], i)
        elif s < i:
            return self._find(ts[:mid], i)
        else:
            return (s, e)


def run():
    s1 = input()
    n = int(input())

    matcher = IndexMatch(s1)
    for _ in range(n):
        s2 = input()
        if matcher.match(s2):
            print(1)
        else:
            print(0)


if __name__ == '__main__':
    run()

Submission status: Time Limit Exceeded

Solution code:
T = input()
P = int(input())
for i in range(P):
    tmp = input()
    if tmp in T:
        print(1)
    else:
        print(0)

Submission status: Time Limit Exceeded

Solution code:
import re
T = input()
P = int(input())
for i in range(P):
    tmp = re.compile(input())
    obj = re.search(tmp,T)
    if obj:
        print(1)
    else:
        print(0)

Submission status: Time Limit Exceeded

Solution code:
base = 127
mask = (1 << 32) - 1


def calc_hash(f, pl, tl):
    dl = tl - pl
    tmp = []

    t = 1
    for _ in range(pl):
        t = (t * base) & mask
    e = 0
    for i in range(pl):
        e = (e * base + f[i]) & mask
    for i in range(dl):
        tmp.append(e)
        e = (e * base - t * f[i] + f[i + pl]) & mask
    tmp.append(e)
    return tmp


t = [ord(c) for c in input().strip()]
tl = len(t)
q = int(input())
h = dict()
while q:
    p = [ord(c) for c in input().strip()]
    pl = len(p)
    if pl > tl:
        print(0)
        q -= 1
        continue
    if pl > 10:
        keys = calc_hash(p, 10, pl)
        keys0, keys1 = keys[0], keys[1:pl - 9]
        if pl not in h:
            hash_array = h[10] = calc_hash(t, 10, tl)
        else:
            hash_array = h[10]
        for idx, hash in enumerate(hash_array):
            if keys0 == hash and hash_array[idx + 1:idx + pl - 9] == keys1:
                print(1)
                break
        else:
            print(0)
    else:
        key = calc_hash(p, pl, pl).pop() & mask
        if pl not in h:
            h[pl] = calc_hash(t, pl, tl)
        print(1 if key in h[pl] else 0)
    q -= 1

Submission status: Time Limit Exceeded

Solution code:
base = 127
mask = (1 << 32) - 1


def calc_hash(f, pl, tl, with_array):
    dl = tl - pl
    tmp = []

    t = 1
    for _ in range(pl):
        t = (t * base) & mask
    e = 0
    for i in range(pl):
        e = (e * base + f[i]) & mask
    for i in range(dl):
        tmp.append(e)
        e = (e * base - t * f[i] + f[i + pl]) & mask
    tmp.append(e)
    if with_array:
        return set(tmp), tmp
    else:
        return set(tmp)


t = [ord(c) for c in input().strip()]
tl = len(t)
q = int(input())
h = dict()
while q:
    p = [ord(c) for c in input().strip()]
    pl = len(p)
    if pl > tl:
        print(0)
        q -= 1
        continue
    if pl >= 10:
        keys_set, keys_array = calc_hash(p, 10, pl, with_array=True)
        keys0, keys1 = keys_array[0], keys_array[1:pl - 9]
        if pl not in h:
            hash_set, hash_array = h[10] = calc_hash(t, 10, tl, with_array=True)
        else:
            hash_set, hash_array = h[10]

        if keys_set.issubset(hash_set):
            for idx, hash in enumerate(hash_array):
                if keys0 == hash and hash_array[idx + 1:idx + pl - 9] == keys1:
                    print(1)
                    break
            else:
                print(0)
        else:
            print(0)
    else:
        key = calc_hash(p, pl, pl, with_array=False).pop() & mask
        if pl not in h:
            h[pl] = calc_hash(t, pl, tl, with_array=False)
        print(1 if key in h[pl] else 0)
    q -= 1

Submission status: Time Limit Exceeded

Solution code:
base = 127
mask = (1 << 32) - 1


def calc_hash(f, pl, tl):
    dl = tl - pl
    tmp = set()

    t = 1
    for _ in range(pl):
        t = (t * base) & mask
    e = 0
    for i in range(pl):
        e = (e * base + f[i]) & mask
    for i in range(dl):
        tmp.add(e)
        e = (e * base - t * f[i] + f[i + pl]) & mask
    tmp.add(e)
    return tmp


t = [ord(c) for c in input().strip()]
tl = len(t)
q = int(input())
h = dict()
while q:
    p = [ord(c) for c in input().strip()]
    pl = len(p)
    if pl > tl:
        print(0)
        q -= 1
        continue
    bs = min(20, pl)
    keys = calc_hash(p, bs, pl)
    if bs not in h:
        h[bs] = calc_hash(t, bs, tl)
    print(1 if keys.issubset(h[bs]) else 0)
    q -= 1

Submission status: Time Limit Exceeded

Solution code:
from __future__ import print_function
t = raw_input()
n = int(raw_input())
[print(1) if raw_input() in t else print(0) for x in xrange(n)]

Submission status: Time Limit Exceeded

Solution code:
T = input()
Q = int(input())
for line in range(Q):
    P = input()
    print(1 if P in T else 0)

Submission status: Time Limit Exceeded

Solution code:
T = input()
Q = int(input())
P = [input() for i in range(Q)]
for p in P:
	print(1 if T.find(p) != -1 else 0)

Submission status: Time Limit Exceeded

Solution code:
T = input()
n = int(input())
for i in range(n):
 p = input()
 print(1 if p in T else 0)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    # ???????????\???
    # T = 'aabaaa'
    seartch_pattern = []
    # seartch_pattern.append('aa')
    # seartch_pattern.append('ba')
    # seartch_pattern.append('bb')
    # seartch_pattern.append('xyz')

    T = input()
    num = int(input())
    for _ in range(num):
        seartch_pattern.append(input())

    # ????´¢??????
    results = []
    for p in seartch_pattern:
        if p in T:
            results.append(1)
        else:
            results.append(0)

    # ???????????¨???
    for r in results:
        print(r)

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8

def MSM(T,P):
    Tlist=list(T)
    Plist=list(P)
    if len(Tlist)<len(Plist):
        return 0
    for i in range(len(Tlist)):
        ans=0
        if Tlist[i]==Plist[0]:
            ans+=1
            if len(Plist)>1 and len(Tlist[i:])>=len(Plist):
                for j in range(1,len(Plist)):
                    if Plist[j]==Tlist[i+j] and i+j<=len(Tlist):
                        ans+=1
        if ans==len(Plist):
            return 1
    return 0

if __name__=="__main__":
    T=input()
    n=int(input())
    ans=[]
    for i in range(n):
        P=input()
        ans.append(MSM(T,P))
    for i in range(n):
        print(ans[i])

Submission status: Time Limit Exceeded

Solution code:
s=input()
for _ in range(int(input())):print(int(input() in s))

Submission status: Time Limit Exceeded

Solution code:
s=input()
n=int(input())
for _ in range(n):
    b=input()
    print(int(b in s))

Submission status: Time Limit Exceeded

Solution code:
s=input()
for _ in range(int(input())):print([0,1][input() in s])

Submission status: Time Limit Exceeded

Solution code:
import sys
CSIZE = 256
buff = input()
n = int(input())



def make_BM_table(pattern):
    table = [len(pattern) ] * CSIZE
    for i in range(len(pattern)):
        dist = len(pattern) - i - 1
        table[ord(pattern[i])] = dist
    return table

def BM_search(pattern,buff):
    table = make_BM_table(pattern)
    i = len(pattern) - 1
    while i < len(buff) :
        for k in range(len(pattern)):
            
            if pattern[len(pattern)-k-1] != buff[i - k]:
                i += max(table[ord(buff[i-k])] -k-1 ,1)
                break
        else: 
            print("1")
            break
    else:
        print("0")
        
for i in range(n):
    pattern = input()
    BM_search(pattern, buff)

Submission status: Time Limit Exceeded

Solution code:
import sys
T = input()
t = len(T)
n = int(input())
P = sys.stdin.readlines()
for i in range(n):
    p = P[i]
    m = len(p)-1
    for k in range(t-m+1):
        for i in range(m):
            if p[i] != T[k+i]:
                break
        else:
            print(1)
            break
    else:
        print(0)

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import deque
T = input()
t = len(T)
n = int(input())
P = deque(sys.stdin.readlines())
for i in range(n):
    p = P.popleft()
    m = len(p)-1
    for k in range(t-m+1):
        for i in range(m):
            if p[i] != T[k+i]:
                break
        else:
            print(1)
            break
    else:
        print(0)

Submission status: Time Limit Exceeded

Solution code:
line = input()
n = int(input())

for i in range(n):
    if line.find(input()) == -1:
        print(0)
    else:
        print(1)

Submission status: Time Limit Exceeded

Solution code:
line = input()
n = int(input())

for i in range(n):
    if input() in line:
        print(1)
    else:
        print(0)

Submission status: Time Limit Exceeded

Solution code:

def isEqual(T,P):
    for i in range(len(T)-len(P)+1):
        if T[i:i+len(P)] == P:
            return 1
    return 0

if __name__ == '__main__':
    T = input()
    n = int(input())

    for i in range(n):
        P = input()
        print(isEqual(T,P))

Submission status: Time Limit Exceeded

Solution code:

def isEqual(T,P):
    for i in range(len(T)-len(P)+1):
        if T[i:i+len(P)] == P:
            return 1
    return 0

if __name__ == '__main__':
    T = input()
    n = int(input())

    for i in range(n):
        P = input()
        print(isEqual(T,P))

Submission status: Time Limit Exceeded

Solution code:

def isEqual(T,P):
    for i in range(len(T)-len(P)+1):
        if T[i:i+len(P)] == P:
            return 1
    return 0

T = input()
n = int(input())

for i in range(n):
    P = input()
    print(isEqual(T,P))

Submission status: Time Limit Exceeded

Solution code:
T = input()
n = int(input())
for i in range(n):
    P = input()
    if P in T:
        print(1)
    else:
        print(0)

Submission status: Time Limit Exceeded

Solution code:
def check(T,LT,p):
    lp=len(p)
    for i in range(LT-lp+1):
        if T[i:i+lp]==p:
            print("1")
            return
    print("0")

T = input()
LT = len(T)
q = int(input())
for i in range(q):
    p = input()
    check(T,LT,p)

Submission status: Time Limit Exceeded

Solution code:
T = input()
q = int(input())
for i in range(q):
    p = input()
    if p in T:
        print("1")
    else:
        print("0")

Submission status: Time Limit Exceeded

Solution code:
T = input()
n = int(input())


for i in range(n):
    P = input()

    list = T.split(P)

    if T == list[0]:
        print(0)
    else:
        print(1)

Submission status: Time Limit Exceeded

Solution code:

def search1(T,P):
    
    if P in T:
        print(1)
    else:
        print(0)

def search2(T,line):
    
    if line in T:
        return True
    else:
        return False
    

T = input()
n = int(input())


for i in range(n):
    
    P = input()
    
    if len(P) < 500:
        
        search1(T,P)

    else:

        line = P[0:250]
        if search2(T,line):
            search1(T,P)
        else:
            print(0)

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8

# ?§????????????????????????????
def make_BM_table(P):
    CSIZE = 128
    bm_table = [len(P)]*CSIZE

    for i in range(len(P)-1):
        bm_table[ord(P[i])] = len(P)-i-1
        
    return bm_table

# ?????????????´¢
def BM_string_search(T,P):
    
    if len(P) > len(T):
        return False

    # ?§????????????????????????????
    bm_table = make_BM_table(P)

    i = len(P)-1

    while i < len(T):
        j = len(P)-1

        while T[i] == P[j]:
            
            # ??????
            if j == 0:
                return True

            i -= 1
            j -= 1

        i += max(bm_table[ord(T[i])],len(P)-j)

    return False


if __name__ == '__main__':

    # ?????????????????\???
    T = input()
    # ????´¢?????????????????°?????\???
    n = int(input())

    # ????????????????????????????????????????????\???
    for i in range(n):
        P = input()
    
        if BM_string_search(T,P):
            print(1)
        else:
            print(0)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import re

original_string = input()
check_string_count = int(input())
for count in range(check_string_count):
    checker = input()
    print(1 if re.search(checker, original_string) else 0)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
original_string = input()
check_string_count = int(input())
checkers = [input() for i in range(check_string_count)]
for checker in checkers:
    print(1 if checker in original_string else 0)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
original_string = input()
check_string_count = int(input())
checkers = [input() for i in range(check_string_count)]
for checker in checkers:
    if len(checker) > 10:
        half_checker = checker[0:int(len(checker)/2)]
        if half_checker not in original_string:
            continue
    print(1 if checker in original_string else 0)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
original_string = list(map(ord, list(input())))
check_string_count = int(input())
checkers = [list(map(ord,list(input()))) for i in range(check_string_count)]
for checker in checkers:
    found = False
    if len(checker) > len(original_string):
        print(0)
        continue
    for index in range(0, len(original_string)):
        if (len(original_string)-len(checker)) < index:
            break
        if original_string[index] == checker[0]:
            found = True
            for checker_index in range(len(checker)):
                #print("{0},{1}".format(index,checker_index))
                if checker[checker_index] != original_string[index + checker_index]:
                    found = False
                    break
            if found:
                print(1)
                break
    if not found:
        print(0)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
original_string = input()
check_string_count = int(input())
checkers = [input() for i in range(check_string_count)]
for checker in checkers:
    skip = False
    for char in list(checker):
        if char not in original_string:
            skip = True
            break
    if skip:
        print(0)
        continue
    print(1 if checker in original_string else 0)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
original_string = input()[::-1]
check_string_count = int(input())
checkers = [input()[::-1] for i in range(check_string_count)]
for checker in checkers:
    for char in list(checker):
        if char not in original_string:
            checker = "#"
            break
    print(1 if checker in original_string else 0)