Em bị lỗi Time Limit Exceed (chạy quá thời gian). Các expert giúp em với ạ. Em chưa nghĩ được cách khác phục
Đây là đề bài ạ:
Đây là code của em:
ans=0
ppppp=input()
a,b=ppppp.split()
a=int(a)-1
b=int(b)
list1=[]
list2=[]
p=input()
p=input()
for siii in p:
list1.append(siii)
for i in range (a-1):
p=input()
e=i-1
o=-1
for s in p:
o=o+1
list1[o]=list1[o]+str(s)
status=False
while a>0:
for i in list1:
if i in list2:
status=True
else:
list2.append(i)
if status==True:
break
else:
index=-1
for j in list1:
index=index+1
g=j[1:]
list1[index]=g
list2=[]
a=a-1
ans=ans+1
print(ans)