D - パターンマッチ

D - パターンマッチ

O(N) 使用可能文字を全探索します。

import math
import heapq
import itertools
from functools import reduce

def is_match(T, S):
    for i in range(0, len(S) - len(T) + 1):
        ok = True
        for j in range(0, len(T)):
            if S[i + j] != T[j] and T[j] != '.':
                ok = False
        if ok:
            return True
    return False

 
# main
def main():
    C = "abcdefghijklmnopqrstuvwxyz."
    S = str(input())

    M = []

    for T in C:
        if is_match(T, S):
            M.append(T)

    for c1 in C:
        for c2 in C:
            T = c1 + c2
            if is_match(T, S):
                M.append(T)

    for c1 in C:
        for c2 in C:
            for c3 in C:
                T = c1 + c2 + c3
                if is_match(T, S):
                    M.append(T)

    print(len(M))

# エントリポイント
if __name__ == '__main__':
    main()