結果

問題 No.1909 Detect from Substrings
ユーザー mkawa2mkawa2
提出日時 2022-04-22 22:15:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 285 ms / 2,000 ms
コード長 1,963 bytes
コンパイル時間 1,539 ms
コンパイル使用メモリ 86,332 KB
実行使用メモリ 161,136 KB
最終ジャッジ日時 2023-09-06 08:47:46
合計ジャッジ時間 10,913 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,188 KB
testcase_01 AC 71 ms
71,224 KB
testcase_02 AC 69 ms
71,200 KB
testcase_03 AC 83 ms
75,368 KB
testcase_04 AC 80 ms
75,612 KB
testcase_05 AC 93 ms
76,324 KB
testcase_06 AC 99 ms
76,864 KB
testcase_07 AC 101 ms
76,836 KB
testcase_08 AC 248 ms
160,028 KB
testcase_09 AC 225 ms
144,244 KB
testcase_10 AC 158 ms
110,208 KB
testcase_11 AC 150 ms
110,804 KB
testcase_12 AC 133 ms
89,344 KB
testcase_13 AC 265 ms
159,876 KB
testcase_14 AC 279 ms
161,136 KB
testcase_15 AC 247 ms
153,944 KB
testcase_16 AC 147 ms
92,376 KB
testcase_17 AC 125 ms
77,984 KB
testcase_18 AC 121 ms
77,252 KB
testcase_19 AC 121 ms
76,916 KB
testcase_20 AC 122 ms
77,328 KB
testcase_21 AC 251 ms
147,876 KB
testcase_22 AC 268 ms
149,692 KB
testcase_23 AC 162 ms
103,304 KB
testcase_24 AC 164 ms
104,052 KB
testcase_25 AC 139 ms
88,960 KB
testcase_26 AC 273 ms
157,396 KB
testcase_27 AC 255 ms
142,480 KB
testcase_28 AC 252 ms
144,720 KB
testcase_29 AC 285 ms
143,536 KB
testcase_30 AC 274 ms
144,712 KB
testcase_31 AC 281 ms
144,812 KB
testcase_32 AC 274 ms
144,708 KB
testcase_33 AC 282 ms
158,400 KB
testcase_34 AC 280 ms
144,956 KB
testcase_35 AC 285 ms
141,744 KB
testcase_36 AC 279 ms
144,756 KB
testcase_37 AC 283 ms
141,828 KB
testcase_38 AC 278 ms
144,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import pypyjit

pypyjit.set_param('max_unroll_recursion=-1')

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):
    l = r = 0
    pre = []
    for i in range(m):
        pre.append(s[i])
        if s[i] != t[i]:
            l = i+1
            break
    pos = []
    for i in range(m)[::-1]:
        pos.append(t[i])
        if s[i] != t[i]:
            r=i+1
            break
    for i in range(l,r):pre.append(s[i])
    return pre+pos[::-1]

def check(t):
    if not t: return False
    for s in ss:
        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