結果

問題 No.1909 Detect from Substrings
ユーザー 👑 rin204
提出日時 2022-04-22 21:34:04
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 896 bytes
コンパイル時間 285 ms
コンパイル使用メモリ 82,492 KB
実行使用メモリ 702,376 KB
最終ジャッジ日時 2024-06-24 02:39:03
合計ジャッジ時間 34,185 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18 TLE * 1 MLE * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10 ** 9)

n, m = map(int, input().split())
lst = [input() for _ in range(n)]
S = lst[0]
T = lst[1]
tmp = []
ans = 0

def ok():
    for S in lst:
        p = 0
        for t in tmp:
            if S[p] == t:
                p += 1
                if p == m:
                    break
        if p != m:
            return False
    return True
    

def dfs(sp, tp, x):
    if sp == m and tp == m:
        global ans
        if ok():
            ans += 1
        return
    if sp < m and tp < m and S[sp] == T[tp]:
        tmp.append(S[sp])
        dfs(sp + 1, tp + 1, x)
        tmp.pop()
    else:
        if sp < m and not x & 1:
            tmp.append(S[sp])
            dfs(sp + 1, tp, x ^ 1)
            tmp.pop()
        if tp < m and not x & 2:
            tmp.append(T[tp])
            dfs(sp, tp + 1, x ^ 2)
            tmp.pop()

dfs(0, 0, 0)
print(ans)
0