結果

問題 No.1909 Detect from Substrings
ユーザー ikomaikoma
提出日時 2022-04-22 22:40:59
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,662 bytes
コンパイル時間 439 ms
コンパイル使用メモリ 87,236 KB
実行使用メモリ 160,664 KB
最終ジャッジ日時 2023-09-06 09:19:12
合計ジャッジ時間 7,786 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,384 KB
testcase_01 AC 72 ms
71,312 KB
testcase_02 AC 72 ms
71,324 KB
testcase_03 AC 77 ms
75,332 KB
testcase_04 AC 76 ms
75,304 KB
testcase_05 AC 83 ms
76,660 KB
testcase_06 AC 87 ms
77,140 KB
testcase_07 AC 87 ms
77,300 KB
testcase_08 AC 182 ms
130,512 KB
testcase_09 AC 144 ms
116,736 KB
testcase_10 AC 122 ms
103,916 KB
testcase_11 AC 107 ms
94,740 KB
testcase_12 AC 98 ms
88,564 KB
testcase_13 WA -
testcase_14 AC 160 ms
132,872 KB
testcase_15 AC 165 ms
119,664 KB
testcase_16 AC 111 ms
87,840 KB
testcase_17 AC 94 ms
77,964 KB
testcase_18 AC 95 ms
77,944 KB
testcase_19 AC 96 ms
77,528 KB
testcase_20 AC 96 ms
77,268 KB
testcase_21 WA -
testcase_22 AC 180 ms
129,180 KB
testcase_23 WA -
testcase_24 AC 115 ms
98,504 KB
testcase_25 AC 107 ms
85,704 KB
testcase_26 AC 173 ms
125,612 KB
testcase_27 AC 173 ms
125,472 KB
testcase_28 AC 157 ms
132,932 KB
testcase_29 AC 208 ms
146,292 KB
testcase_30 WA -
testcase_31 AC 207 ms
142,004 KB
testcase_32 WA -
testcase_33 AC 207 ms
148,228 KB
testcase_34 WA -
testcase_35 AC 205 ms
143,392 KB
testcase_36 WA -
testcase_37 AC 206 ms
143,348 KB
testcase_38 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N,M=map(int,input().split())
S=[input().strip() for _ in range(N)]

base1 = []
base2 = []
s0,s1=S[0],S[1]
for i in range(M):
    s0i=s0[i]
    s1i=s1[i]
    if s0[i]==s1[i]:
        base1.append(s0i)
        base2.append(s0i)
    else:
        if i==M-1:
            base1.append(s0i)
            base1.append(s1i)
            base2.append(s1i)
            base2.append(s0i)
            break
        if s0[i+1]==s1[i+1]:
            base1.append(s0i)
            base1.append(s1i)
            base2.append(s1i)
            base2.append(s0i)
            for j in range(i+2,M):
                base1.append(s0[j])
                base2.append(s1[j])
        else:
            if s0[i+1]==s1i:
                base1.append(s0i)
                base1.append(s1i)
                base1.append(s1[i+1])
                for j in range(i+2,M):
                    base1.append(s1[j])
            if s1[i+1]==s0i:
                base2.append(s1i)
                base2.append(s0i)
                base2.append(s0[i+1])
                for j in range(i+2,M):
                    base2.append(s0[j])
        break
base1 = "".join(base1) if base1 is not None else None
base2 = "".join(base2) if base2 is not None else None

def judge(s,b):
    j=0
    for i,ss in enumerate(s):
        if ss!=b[j]:
            j+=1
            if j>=len(b) or ss!=b[j]:
                return False
            if j>i+1:return False
        j+=1
    return j<=len(b)

ans=0
for b in [base1,base2]:
    if b is None:continue
    if len(b)!=M+1:continue
    for s in S:
        if judge(s,b):continue
        break
    else:
        ans+=1
print(ans)
0