結果

問題 No.1909 Detect from Substrings
ユーザー 👑 rin204rin204
提出日時 2022-04-22 21:34:40
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 603 ms / 2,000 ms
コード長 896 bytes
コンパイル時間 1,027 ms
コンパイル使用メモリ 10,860 KB
実行使用メモリ 115,920 KB
最終ジャッジ日時 2023-09-06 07:54:47
合計ジャッジ時間 12,801 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,208 KB
testcase_01 AC 16 ms
8,240 KB
testcase_02 AC 16 ms
8,152 KB
testcase_03 AC 17 ms
8,356 KB
testcase_04 AC 21 ms
8,412 KB
testcase_05 AC 40 ms
8,892 KB
testcase_06 AC 45 ms
9,496 KB
testcase_07 AC 46 ms
9,468 KB
testcase_08 AC 166 ms
77,208 KB
testcase_09 AC 34 ms
16,364 KB
testcase_10 AC 152 ms
52,012 KB
testcase_11 AC 73 ms
34,432 KB
testcase_12 AC 118 ms
30,596 KB
testcase_13 AC 332 ms
115,844 KB
testcase_14 AC 330 ms
115,888 KB
testcase_15 AC 332 ms
115,840 KB
testcase_16 AC 145 ms
30,616 KB
testcase_17 AC 94 ms
11,372 KB
testcase_18 AC 94 ms
9,720 KB
testcase_19 AC 94 ms
9,480 KB
testcase_20 AC 91 ms
9,476 KB
testcase_21 AC 332 ms
115,852 KB
testcase_22 AC 331 ms
115,784 KB
testcase_23 AC 189 ms
51,960 KB
testcase_24 AC 184 ms
51,988 KB
testcase_25 AC 138 ms
30,624 KB
testcase_26 AC 334 ms
115,792 KB
testcase_27 AC 328 ms
115,824 KB
testcase_28 AC 329 ms
115,908 KB
testcase_29 AC 565 ms
115,784 KB
testcase_30 AC 527 ms
115,836 KB
testcase_31 AC 588 ms
115,920 KB
testcase_32 AC 525 ms
115,840 KB
testcase_33 AC 603 ms
115,876 KB
testcase_34 AC 517 ms
115,876 KB
testcase_35 AC 564 ms
115,800 KB
testcase_36 AC 523 ms
115,804 KB
testcase_37 AC 583 ms
115,840 KB
testcase_38 AC 527 ms
115,824 KB
権限があれば一括ダウンロードができます

ソースコード

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