結果

問題 No.1909 Detect from Substrings
ユーザー titia
提出日時 2022-04-23 01:26:13
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 783 ms / 2,000 ms
コード長 920 bytes
コンパイル時間 261 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 13,776 KB
最終ジャッジ日時 2024-06-24 06:58:02
合計ジャッジ時間 18,157 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

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

for i in range(M):
    if S[0][i]!=S[1][i]:
        T1=S[0][:i]+S[1][i]+S[0][i:]
        T2=S[1][:i]+S[0][i]+S[1][i:]
        break

ANS=0

for i in range(N):
    s=S[i]
    ind2=0
    c=0
    for ind in range(M):
        if s[ind]==T1[ind2]:
            ind2+=1
        else:
            c+=1
            if s[ind]==T1[ind2+1]:
                ind2+=2
            else:
                c=100
                break
    if c>=2:
        break
    
else:
    ANS+=1

    
for i in range(N):
    s=S[i]
    ind2=0
    c=0
    for ind in range(M):
        if s[ind]==T2[ind2]:
            ind2+=1
        else:
            c+=1
            if s[ind]==T2[ind2+1]:
                ind2+=2
            else:
                c=100
                break
    if c>=2:
        break
    
else:
    ANS+=1

print(ANS)

    

0