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

bhn Test 8 python [6] // Problem 1196. History Exam 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
Oleg Baskakov Re: Test 8 python [3] // Problem 1196. History Exam 25 May 2016 15:27
Ilanya Klirik Re: Test 8 python [2] // Problem 1196. History Exam 16 Aug 2017 15:31
There is "Time limit exceeded" with binary search too.
ivan228 Re: Test 8 python [1] // Problem 1196. History Exam 16 Oct 2018 20:34
ToadMonster Re: Test 8 python // Problem 1196. History Exam 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
SMMaster Re: Test 8 python // Problem 1196. History Exam 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)