【問題】
ERROR: The request could not be satisfied

【方針】最初は正規表現を用いたが、遅くてTLEになった。頭の文字をfindで探して、お尻の文字をrfindで探す。その間をCounterで探すという作戦にした。
【解答】
#input
n = int(input())
s = str(input())
#output
answer = 0
from collections import Counter
for i in range(10):
first_pos = s.find("{0}".format(i))
if first_pos != -1:
for j in range(10):
last_pos = s.rfind("{0}".format(j))
if (last_pos != -1):
if last_pos > first_pos:
answer += len(Counter(s[first_pos+1:last_pos]))
print(answer)
【提出結果】
ERROR: The request could not be satisfied
【追記】python3のfastestをみると、Counterを用いると遅くなる。\(\times 10\)程度なので、その間もforで探しても良かった。
コメント