Time Constraints in Competitive Programming

The Explanation will be given tomorrow, because of "Time Constraints"  for the night.

Hasta Manana! 

"""

The below one is an algo which was accepted after a Time Limit Exceeded 
TestCase Failure
"""
N=int(input())
words={}
for _ in range(N):
    word=input()
    if word not in words:
        words[word]=1
    elif word in words:
        words[word]+=1
print(len(words))
for elem in words:
    print(words[elem],end=" ") 
    
"""
The below algo was the previous one which wasn't accepted because of 
Time Constraints
"""
N=int(input())
words=[]
diff_counter=0
for _ in range(N):
    word=input()
    if word not in words:
        diff_counter=diff_counter+1
    words.append(word)
print(diff_counter)
ls1=[]
for elem in words:
    if elem not in ls1:
        print(words.count(elem),end=" ")
        ls1.append(elem)

Comments

Popular Posts