結果

問題 No.1909 Detect from Substrings
ユーザー shotoyooshotoyoo
提出日時 2022-04-22 21:25:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 160 ms / 2,000 ms
コード長 1,935 bytes
コンパイル時間 1,268 ms
コンパイル使用メモリ 86,912 KB
実行使用メモリ 117,316 KB
最終ジャッジ日時 2023-09-06 07:41:55
合計ジャッジ時間 9,160 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
72,244 KB
testcase_01 AC 91 ms
71,936 KB
testcase_02 AC 89 ms
72,212 KB
testcase_03 AC 114 ms
77,396 KB
testcase_04 AC 104 ms
77,096 KB
testcase_05 AC 113 ms
80,828 KB
testcase_06 AC 123 ms
84,952 KB
testcase_07 AC 118 ms
85,028 KB
testcase_08 AC 150 ms
116,984 KB
testcase_09 AC 129 ms
102,276 KB
testcase_10 AC 141 ms
98,120 KB
testcase_11 AC 127 ms
95,892 KB
testcase_12 AC 124 ms
89,200 KB
testcase_13 AC 132 ms
102,352 KB
testcase_14 AC 141 ms
108,140 KB
testcase_15 AC 148 ms
111,756 KB
testcase_16 AC 129 ms
90,952 KB
testcase_17 AC 120 ms
84,848 KB
testcase_18 AC 121 ms
84,856 KB
testcase_19 AC 122 ms
85,052 KB
testcase_20 AC 124 ms
84,832 KB
testcase_21 AC 148 ms
110,700 KB
testcase_22 AC 154 ms
117,316 KB
testcase_23 AC 126 ms
92,292 KB
testcase_24 AC 125 ms
92,948 KB
testcase_25 AC 123 ms
89,428 KB
testcase_26 AC 148 ms
113,800 KB
testcase_27 AC 151 ms
114,300 KB
testcase_28 AC 139 ms
108,332 KB
testcase_29 AC 146 ms
109,760 KB
testcase_30 AC 155 ms
114,144 KB
testcase_31 AC 143 ms
108,268 KB
testcase_32 AC 154 ms
114,308 KB
testcase_33 AC 138 ms
105,520 KB
testcase_34 AC 150 ms
114,740 KB
testcase_35 AC 143 ms
109,024 KB
testcase_36 AC 153 ms
114,740 KB
testcase_37 AC 145 ms
108,896 KB
testcase_38 AC 160 ms
114,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys, random
input = lambda : sys.stdin.readline().rstrip()

write = lambda x: sys.stdout.write(x+"\n"); writef = lambda x: print("{:.12f}".format(x))
debug = lambda x: sys.stderr.write(x+"\n")
YES="Yes"; NO="No"; pans = lambda v: print(YES if v else NO); inf=10**18
LI = lambda : list(map(int, input().split()))
def dlist(*l, fill=0):
    if len(l)==1:
        return [fill]*l[0]
    ll = l[1:]
    return [dlist(*ll, fill=fill) for _ in range(l[0])]
sys.setrecursionlimit(3*10**5+10)

n,m = list(map(int, input().split()))
ss = [[ord(c)-ord("a") for c in input()] for _ in range(n)]
se = set()
p = None
def ok(val, s0):
    j = 0
    for i in range(m+1):
        if j<m and val[i]==s0[j]:
            j += 1
    return j==m
def sub(s0,s1):
    if s0==s1:
        return 1, None
    for i in range(m):
        if s0[i]!=s1[i]:
            v0 = s0[:i] + [s0[i]] + s1[i:]
            v1 = s0[:i] + [s1[i]] + s0[i:]
            val = 0
            res0 = (ok(v0, s0) and ok(v0, s1))
            res1 = (ok(v1, s0) and ok(v1, s1))
            if res0 and res1:
                return 1, (v0, v1)
            elif res0:
                return 1, v0
            elif res1:
                return 1, v1
            else:
                return 0, None
for s in ss:
    if p is not None:
        if p==s:
            continue
        else:
            v, res = sub(p,s)
            if v==0:
                ans = 0
                break
            elif res is None:
                continue
            else:
                if type(res)==tuple:
                    ans = 0
                    ans += all(ok(res[0], s) for s in ss)
                    ans += all(ok(res[1], s) for s in ss)
                else:
                    if all(ok(res, s) for s in ss):
                        ans = 1
                    else:
                        ans = 0
                break
    else:
        p = s
else:
    ans = 26*(m+1)
print(ans)
0