ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1196. History Exam

Show all messages Hide all messages

Test 8 python bhn 25 May 2016 14:36
time limit exceed on python3
there a code:
a=[]
for i in range(int(input())):
    a.append(input())
b=[]
n=0
for j in range(int(input())):
    if input() in a:
        n+=1
print(n)

please help me
Re: Test 8 python Oleg Baskakov 25 May 2016 15:27
Re: Test 8 python Ilanya Klirik 16 Aug 2017 15:31
There is "Time limit exceeded" with binary search too.
Re: Test 8 python ToadMonster 26 May 2016 14:52
Probably you should use data structure with quick search, like python set/dictionary.

https://docs.python.org/3/tutorial/datastructures.html
Re: Test 8 python SMMaster 30 Dec 2019 14:31
import sys
ll = set()
for i in range(int(sys.stdin.readline())):
    ll.add(sys.stdin.readline())
n = 0
for j in range(int(sys.stdin.readline())):
    if sys.stdin.readline() in ll:
        n += 1
print(n)