結果

問題 No.1909 Detect from Substrings
ユーザー mkawa2mkawa2
提出日時 2022-04-22 21:59:19
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 2,029 bytes
コンパイル時間 277 ms
コンパイル使用メモリ 10,948 KB
実行使用メモリ 14,256 KB
最終ジャッジ日時 2023-09-06 08:24:42
合計ジャッジ時間 7,430 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,108 KB
testcase_01 AC 18 ms
8,096 KB
testcase_02 AC 17 ms
8,080 KB
testcase_03 AC 893 ms
8,504 KB
testcase_04 AC 67 ms
8,748 KB
testcase_05 AC 96 ms
9,176 KB
testcase_06 AC 105 ms
9,740 KB
testcase_07 AC 170 ms
9,904 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 TLE -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = (1 << 63)-1
# inf = (1 << 31)-1
md = 10**9+7
# md = 998244353

def compare(s, t):
    a = b = 0
    res = []
    for i in range(m-1):
        if s[i+a] != t[i+b]:
            if a == 0 and s[i+1] == t[i]:
                res.append(s[i])
                a = 1
            elif a == 1 and b == 0 and s[i+1] == t[i+1]:
                res.append(t[i])
                b = 1
            else:
                return []
        res.append(s[i+a])
    if a == 0: res.append(s[-1])
    if b == 0: res.append(t[-1])
    return res

def check(t):
    if not t: return False
    for s in ss[2:]:
        if ng(s, t): return False
    return True

def ng(s, t):
    t = iter(t)
    for c in s:
        if c not in t: return True
    return False

def dfs(j=0):
    if j == m+1: return 1
    res = 0
    for c in range(26):
        c = chr(c+97)
        ii = []
        for i, s in enumerate(ss):
            if j-jump[i] < m and s[j-jump[i]] != c:
                if jump[i]: break
                jump[i] = 1
                ii.append(i)
        else:
            res += dfs(j+1)
        for i in ii: jump[i] = 0
    return res

n, m = LI()
ss = [SI() for _ in range(n)]

jump = [0]*n
print(dfs())

# tt = set()
#
# t = compare(ss[0], ss[1])
# pDB(t)
# if check(t): tt.add("".join(t))
#
# t = compare(ss[1], ss[0])
# pDB(t)
# if check(t): tt.add("".join(t))
#
# print(len(tt))
0