結果

問題 No.1909 Detect from Substrings
ユーザー gew1fw
提出日時 2025-06-12 19:50:59
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 823 bytes
コンパイル時間 186 ms
コンパイル使用メモリ 82,528 KB
実行使用メモリ 847,740 KB
最終ジャッジ日時 2025-06-12 19:51:09
合計ジャッジ時間 8,050 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 5 MLE * 1 -- * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

def is_subsequence(s, t):
    it = iter(t)
    return all(c in it for c in s)

def main():
    import sys
    input = sys.stdin.read().split()
    idx = 0
    N = int(input[idx])
    idx += 1
    M = int(input[idx])
    idx += 1
    S = []
    for _ in range(N):
        S.append(input[idx])
        idx += 1
    
    # Generate all possible T from S[0]
    s0 = S[0]
    candidates = set()
    for pos in range(M + 1):
        for c in 'abcdefghijklmnopqrstuvwxyz':
            new_t = s0[:pos] + c + s0[pos:]
            candidates.add(new_t)
    
    count = 0
    for t in candidates:
        valid = True
        for s in S[1:]:
            if not is_subsequence(s, t):
                valid = False
                break
        if valid:
            count += 1
    print(count)

if __name__ == "__main__":
    main()
0