結果

問題 No.1909 Detect from Substrings
ユーザー SidewaysOwl
提出日時 2022-04-22 23:14:31
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,831 bytes
コンパイル時間 342 ms
コンパイル使用メモリ 82,692 KB
実行使用メモリ 194,012 KB
最終ジャッジ日時 2024-06-24 04:39:09
合計ジャッジ時間 7,713 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 15 WA * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m = map(int,input().split())
s = [list(input()) for _ in range(n)]
from collections import Counter
diff = 0
flg = True
for i in range(m):
    if s[0][i] != s[1][i]:
        diff += 1

free = -1
if diff == 1:
    tmp =[]
    for i in range(m):
        if s[0][i] != s[1][i]:
            free = i
            tmp.append(s[0][i] + s[1][i])
        else:
            tmp.append(s[0][i])
else:
    for ii in range(2):
        x,y = 0,0
        diff = 0
        tmp =[]
        if ii == 0:s1,s2 = s[0],s[1]
        else:s1,s2 = s[1],s[0]
        for i in range(m-1):
            if (s1[x] != s2[y]) and x == y:
                tmp.append(s1[x])
                x += 1
                idx = i
            if s1[x] != s2[y]:
                diff += 1
            tmp.append(s1[x])
            x+=1
            y+= 1
        tmp.append(s2[-1])
        if diff == 0:
            break
    if diff != 0:
        flg = False
if not flg :
    print(0)
else:
    for i in range(2,n):
        if len(tmp) == m:
            for j in range(m-1):
                if s[i][j] != tmp[j] and j != free:
                    flg = False
                elif s[i][j] != tmp[j]:
                    if s[i][j] in tmp[j] and s[i][j+1] in tmp[j]:
                        tmp = tmp[:free] + [s[i][j]] + [s[i][j+1]] + tmp[free+1::]
                        break
                    else:
                        flg = False
                    
                
        if len(tmp) == m+1:
            x,y = 0,0
            diff = 0
            for j in range(m-1):
                if (s1[i][x] != tmp[y]) and x == y:
                    y += 1
                if s1[i][x] != tmp[y]:
                    diff += 1
        if diff != 0:
            flg = False
    if not flg:
        print(0)
    if len(tmp) == m :
        print(2)
    else:
        print(1)
0