結果

問題 No.1909 Detect from Substrings
ユーザー SidewaysOwlSidewaysOwl
提出日時 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
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
54,628 KB
testcase_01 AC 42 ms
54,500 KB
testcase_02 WA -
testcase_03 AC 50 ms
64,212 KB
testcase_04 AC 52 ms
67,864 KB
testcase_05 AC 79 ms
87,468 KB
testcase_06 AC 106 ms
103,744 KB
testcase_07 AC 108 ms
103,832 KB
testcase_08 AC 204 ms
193,192 KB
testcase_09 AC 211 ms
193,552 KB
testcase_10 AC 161 ms
145,100 KB
testcase_11 AC 163 ms
144,700 KB
testcase_12 AC 143 ms
129,384 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 148 ms
156,408 KB
testcase_31 WA -
testcase_32 AC 155 ms
156,436 KB
testcase_33 WA -
testcase_34 AC 150 ms
156,620 KB
testcase_35 WA -
testcase_36 AC 150 ms
156,540 KB
testcase_37 WA -
testcase_38 AC 155 ms
156,348 KB
権限があれば一括ダウンロードができます

ソースコード

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