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

Test 8 python
Posted by 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
Posted by Oleg Baskakov 25 May 2016 15:27
Re: Test 8 python
Posted by 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
Posted by Ilanya Klirik 16 Aug 2017 15:31
There is "Time limit exceeded" with binary search too.
Re: Test 8 python
Posted by ivan228 16 Oct 2018 20:34
i think that on python i wil not can solve this
Re: Test 8 python
Posted by 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)